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
Sign a File to Create a .p7s (Detached Signature)C example to create a detached signature file (.p7s) for any type file. The signature can be verified by calling VerifyP7S and passing the original filename and the .p7s filename. 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 FreeBSD C++ Libraries HP-UX C++ Libraries BlackBerry QNX C++ Libraries #include <C_CkCrypt2.h> #include <C_CkCertStore.h> #include <C_CkCert.h> void ChilkatSample(void) { HCkCrypt2 crypt; BOOL success; const char * signingCertSubject; const char * pfxFilename; const char * pfxPassword; HCkCertStore certStore; HCkCert cert; const char * inFile; const char * sigFile; 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; } // Use a digital certificate and private key from a PFX file (.pfx or .p12). signingCertSubject = "Acme Inc"; pfxFilename = "/Users/chilkat/testData/pfx/acme.pfx"; pfxPassword = "test123"; certStore = CkCertStore_Create(); success = CkCertStore_LoadPfxFile(certStore,pfxFilename,pfxPassword); if (success != TRUE) { printf("%s\n",CkCertStore_lastErrorText(certStore)); return; } cert = CkCertStore_FindCertBySubjectCN(certStore,signingCertSubject); if (cert == 0 ) { printf("Failed to find certificate by subject common name.\n"); return; } // Tell the crypt component to use this cert. CkCrypt2_SetSigningCert(crypt,cert); // We can sign any type of file, creating a .p7s as output: inFile = "/Users/chilkat/testData/pdf/sample.pdf"; sigFile = "/Users/chilkat/testData/p7s/sample.p7s"; success = CkCrypt2_CreateP7S(crypt,inFile,sigFile); if (success == FALSE) { printf("%s\n",CkCrypt2_lastErrorText(crypt)); CkCert_Dispose(cert); return; } success = CkCrypt2_VerifyP7S(crypt,inFile,sigFile); if (success == FALSE) { printf("%s\n",CkCrypt2_lastErrorText(crypt)); CkCert_Dispose(cert); return; } CkCert_Dispose(cert); printf("Success!\n"); CkCrypt2_Dispose(crypt); CkCertStore_Dispose(certStore); } |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.