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 Opaque Digital SignaturesDemonstrates how to sign a file using a digital certificate. Then loads the opaque signed file, verifies the signature and recovers the original file data and the certificate used for signing. ' Add references to both Chilkat Crypt and Chilkat Certificate.
' Digitally sign a file, then verify the signature and
' fetch the certificate used for signing.
Dim crypt As New ChilkatCrypt2
crypt.UnlockComponent "anything for 30-day trial"
' Get a certificate for signing.
Dim ccs As New ChilkatCreateCS
Dim certStore As ChilkatCertStore
Dim cert As ChilkatCert
' For the purpose of simplifying the example, we do not
' check for errors. To check for errors, make sure the object
' reference returned is not Nothing.
Set certStore = ccs.OpenLocalSystemStore()
Set cert = certStore.FindCertBySubjectE("admin@tagtooga.com")
Dim fileData As Variant
fileData = crypt.ReadFile("hamlet.xml")
Dim signedFileData As Variant
crypt.SetSigningCert cert
signedFileData = crypt.OpaqueSignBytes(fileData)
crypt.WriteFile "hamletSigned.xml.sgn", signedFileData
' Now load the file and verify the signature, recovering the original
' file contents and getting the cert used for signing.
Dim crypt2 As New ChilkatCrypt2
Dim inData As Variant
inData = crypt2.ReadFile("hamletSigned.xml.sgn")
Dim outData As Variant
outData = crypt2.OpaqueVerifyBytes(inData)
If (IsNull(outData)) Then
MsgBox crypt2.LastErrorText
Else
' Get the certificate used to sign..
Dim sigCert As ChilkatCert
Set sigCert = crypt2.GetLastCert()
' Save the output:
crypt2.WriteFile "hamletOriginal.xml", outData
MsgBox "Success: " + cert.SubjectDN
End If
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.