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
PKCS7 SignedData Signature (embeds Signed Data)How to create a PKCS7 signature. The resulting PKCS7 structure is encoded to a printable string using hex or base64 encoding. The data being signed is embedded within the PKCS#7 structure. Demonstrates how to verify the signature and recover the original data.
Chilkat.Crypt2 crypt = new Chilkat.Crypt2(); // Any string argument automatically begins the 30-day trial. bool success; success = crypt.UnlockComponent("30-day trial"); if (success != true) { MessageBox.Show("Crypt component unlock failed"); return; } Chilkat.Cert cert = new Chilkat.Cert(); success = cert.LoadByCommonName("Chilkat Software"); if (success != true) { MessageBox.Show(cert.LastErrorText); return; } // Make sure this certificate has a private key available: bool bHasPrivateKey; bHasPrivateKey = cert.HasPrivateKey(); if (bHasPrivateKey != true) { MessageBox.Show("No private key available for signing."); return; } // Tell the encryption component to use this cert. crypt.SetSigningCert(cert); string strData; strData = "This is the data to be signed."; // Indicate that the PKCS7 signature should be returned // as a base64 encoded string: crypt.EncodingMode = "base64"; // The EncodingMode may be set to other values such as // "hex", "url", "quoted-printable", etc. string strSignatureWithData; strSignatureWithData = crypt.OpaqueSignStringENC(strData); textBox1.Text += strSignatureWithData + "\r\n"; // Now verify the signature against the original data. // Tell the component what certificate to use for verification. crypt.SetVerifyCert(cert); string originalData; originalData = crypt.OpaqueVerifyStringENC(strSignatureWithData); if (originalData == null ) { // The signature verification failed. MessageBox.Show(crypt.LastErrorText); } else { textBox1.Text += originalData + "\r\n"; MessageBox.Show("Signature verified!"); } |
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.