Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Create and Verify Opaque Digital Signatures
Demonstrates 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("test@chilkatsoft.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
|
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.