Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python 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. import com.chilkatsoft.*; public class ChilkatExample { static { try { System.loadLibrary("chilkat"); } catch (UnsatisfiedLinkError e) { System.err.println("Native code library failed to load.\n" + e); System.exit(1); } } public static void main(String argv[]) { CkCrypt2 crypt = new CkCrypt2(); // Any string argument automatically begins the 30-day trial. boolean success; success = crypt.UnlockComponent("30-day trial"); if (success != true) { System.out.println("Crypt component unlock failed"); return; } CkCert cert = new CkCert(); success = cert.LoadByCommonName("Chilkat Software"); if (success != true) { System.out.println(cert.lastErrorText()); return; } // Make sure this certificate has a private key available: boolean bHasPrivateKey; bHasPrivateKey = cert.HasPrivateKey(); if (bHasPrivateKey != true) { System.out.println("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.put_EncodingMode("base64"); // The EncodingMode may be set to other values such as // "hex", "url", "quoted-printable", etc. String strSignatureWithData; strSignatureWithData = crypt.opaqueSignStringENC(strData); System.out.println(strSignatureWithData); // 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. System.out.println(crypt.lastErrorText()); } else { System.out.println(originalData); System.out.println("Signature verified!"); } } } |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.