Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Create and Verify a Digital Signature This example demonstrates how to create and verify a digital signature. It signs an in-memory string, and then verifies it against the digital signature. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Create a detached digital signature for an in-memory string
' using Chilkat Crypt2
Dim crypt As New Chilkat.Crypt2()
' Any string passed to UnlockComponent begins the 30-day trial.
Dim unlocked As Boolean
unlocked = crypt.UnlockComponent("30-day trial")
If Not unlocked Then
MsgBox("Component is not unlocked")
Exit Sub
End If
' Return the digital signature in a base64-encoded string.
crypt.EncodingMode = "base64"
' Select a digital certificate to use for signing.
' This certificate must have the private key already installed
' on the system (usually from a .pfx file).
Dim cert As New Chilkat.Cert()
Dim success As Boolean
success = cert.LoadFromFile("myCert.cer")
If Not success Then
MsgBox(cert.LastErrorText)
Exit Sub
End If
crypt.SetSigningCert(cert)
' Create the digital signature
Dim stringToSign = "Hello World!"
Dim signature As String
signature = crypt.SignStringENC(stringToSign)
If Len(signature) = 0 Then
MsgBox(crypt.LastErrorText)
Exit Sub
End If
TextBox1.Text = signature
' Verify the digital signature against the original text.
' Use a different crypt object for demonstration purposes.
Dim c2 As New Chilkat.Crypt2()
c2.EncodingMode = "base64"
Dim valid As Boolean
valid = c2.VerifyStringENC(stringToSign, signature)
If Not valid Then
MsgBox("The original data has been altered")
Else
MsgBox("The signature has been verified")
End If
Dim cert2 As Chilkat.Cert
cert2 = c2.GetLastCert()
MsgBox("Certifcate: " & cert2.SubjectDN)
' The certificate can now be checked for validity with respect
' to revocation, trusted root, certificate signature, and expiration.
' Refer to the Chilkat.Cert examples for this.
End Sub
Important: The download for this
example does not contain the ChilkatDotNet.dll which |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.