C
C
Workaround for the deprecated Crypt2.SignString method
Shows how to replace the deprecated SignString method. (Chilkat is moving away from the use of CkByteData.)Chilkat C Downloads
#include <C_CkCrypt2.h>
#include <C_CkCert.h>
#include <C_CkByteData.h>
#include <C_CkBinData.h>
void ChilkatSample(void)
{
BOOL success;
HCkCrypt2 crypt;
HCkCert cert;
const char *textToSign;
HCkByteData outData;
const char *base64_sig;
HCkBinData bdSig;
success = FALSE;
crypt = CkCrypt2_Create();
cert = CkCert_Create();
// ...
// Load the cert from a source such as a .pfx/.p12 file, smart card, USB token, Apple keychain, Windows certificate store, etc.
//
success = CkCrypt2_SetSigningCert(crypt,cert);
// Sign the utf-8 byte representation of the text.
CkCrypt2_putCharset(crypt,"utf-8");
textToSign = "This is the text to sign";
// ------------------------------------------------------------------------
// The SignString method is deprecated:
outData = CkByteData_Create();
success = CkCrypt2_SignString(crypt,textToSign,outData);
// ------------------------------------------------------------------------
// Workaround.
// (Chilkat is moving away from using CkByteData)
CkCrypt2_putEncodingMode(crypt,"base64");
base64_sig = CkCrypt2_signStringENC(crypt,textToSign);
// If you want the binary bytes of the signature decoded from base64.
bdSig = CkBinData_Create();
CkBinData_AppendEncoded(bdSig,base64_sig,"base64");
CkCrypt2_Dispose(crypt);
CkCert_Dispose(cert);
CkByteData_Dispose(outData);
CkBinData_Dispose(bdSig);
}