(Unicode C++) RSA Sign using Base64 Private Key
Signs a string using a non-encrypted RSA private key in base64 encoding. Returns the RSA signature as a base64 string.
#include <CkPrivateKeyW.h>
#include <CkStringBuilderW.h>
#include <CkRsaW.h>
void ChilkatSample(void)
{
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkPrivateKeyW privKey;
bool success;
CkStringBuilderW sbPem;
sbPem.AppendLine(L"-----BEGIN RSA PRIVATE KEY-----",true);
sbPem.AppendLine(L"MIIC .... j5A==",true);
sbPem.AppendLine(L"-----END RSA PRIVATE KEY-----",true);
success = privKey.LoadPem(sbPem.getAsString());
if (success != true) {
wprintf(L"%s\n",privKey.lastErrorText());
return;
}
CkRsaW rsa;
success = rsa.ImportPrivateKeyObj(privKey);
if (success != true) {
wprintf(L"%s\n",rsa.lastErrorText());
return;
}
rsa.put_EncodingMode(L"base64");
const wchar_t *strSigned = rsa.openSslSignStringENC(L"12345678");
wprintf(L"%s\n",strSigned);
const wchar_t *strOriginal = rsa.openSslVerifyStringENC(strSigned);
wprintf(L"%s\n",strOriginal);
}
|