Xceed Encryption Library Documentation
Examples / Digitally signing a file (VB example)
In This Topic
    Digitally signing a file (VB example)
    In This Topic
    Visuall Basic Copy Code

    ' Digital signature creation example for VB (single pass) 

    Dim xSign As New XceedSigning ' Instantiate the object
    Call xSign.License( "your license key" ) 

    Dim vaSignature As Variant ' Here is where the signature will go 

    ' Set the signing method type
    Set xSign.SigningMethod = New XceedRSASigningMethod 

    On Error Resume Next 

    ' The following call to SetRandomKeyPair would, in the real world,
    ' be replaced by the assignment of a Private Key to the
    ' PrivateKey property. 

    Call xSign.SigningMethod.SetRandomKeyPair(512, Empty) 

    ' Ok, read the file and create the digital signature 

    Call xSign.ReadFile("c:\temp\source.txt", 0, 0, efpSign, True) 

    ' Fetch the digital signature 

    vaSignature = xSign.SigningMethod.Signature 

    ' Do something with the signature... 

    If Err.Number <> 0 Then
      Call MsgBox("Error 0x" & Hex(Err.Number) & " " & Err.Description) 
    Else
      Call MsgBox("Data signed successfully") 
      Call xSign.ReadFile("c:\temp\source.txt", 0, 0, efpVerify, True) 

      If Err.Number = 0 Then 
        Call MsgBox("Data verified successfully") 
      Else 
        If Err.Number = eerVerifyFailed Then 
          Call MsgBox("Verification of signature failed") 
        Else 
          Call MsgBox("Error 0x" & Hex(Err.Number) & " " & Err.Description) 
        End If 
      End If 
    End If 

    On Error GoTo 0

    Set xSign = Nothing