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
Use Certificate and Private Key PEM Files to Create a Digital SignatureDemonstrates how to load a digital certificate from a PEM file, load it's corresponding private key from a PEM file, save the private key to a key container (if necessary), link the certificate to the key container, and use it to create a digital signature. Downloads: MS Windows Visual C/C++ Libraries Linux/CentOS C/C++ Libraries MAC OS X C/C++ Libraries Solaris C/C++ Libraries C++ Builder Libraries #include <C_CkCert.h> #include <C_CkPrivateKey.h> #include <C_CkCrypt2.h> void ChilkatSample(void) { HCkCert cert; HCkPrivateKey pkey; BOOL success; HCkCrypt2 crypt; cert = CkCert_Create(); // Load the cert from a PEM file; CkCert_LoadFromFile(cert,"cert.pem"); pkey = CkPrivateKey_Create(); // Load the private key from an RSA PEM file: CkPrivateKey_LoadPemFile(pkey,"pkey_rsa.pem"); success = CkCert_SetPrivateKey(cert,pkey); if (success != TRUE) { printf("%s\n",CkCert_lastErrorText(cert)); return; } // Use Chilkat Crypt (a non-freeware component) to create // a digital signature using the certificate w/ private key: crypt = CkCrypt2_Create(); // Any string argument automatically begins the 30-day trial. success = CkCrypt2_UnlockComponent(crypt,"30-day trial"); if (success != TRUE) { printf("%s\n",CkCrypt2_lastErrorText(crypt)); return; } // Tell the crypt component to use this cert. CkCrypt2_SetSigningCert(crypt,cert); // A PKCS7 signature for any type of file content can be created: success = CkCrypt2_CreateP7S(crypt,"license.rtf","license.p7s"); if (success == FALSE) { printf("%s\n",CkCrypt2_lastErrorText(crypt)); return; } printf("%s\n",CkCrypt2_lastErrorText(crypt)); // Verify and restore the original file: CkCrypt2_SetVerifyCert(crypt,cert); success = CkCrypt2_VerifyP7S(crypt,"license.rtf","license.p7s"); if (success == FALSE) { printf("%s\n",CkCrypt2_lastErrorText(crypt)); return; } printf("Success!\n"); CkCert_Dispose(cert); CkPrivateKey_Dispose(pkey); CkCrypt2_Dispose(crypt); } |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.