(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.
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Chilkat.PrivateKey privKey = new Chilkat.PrivateKey();
bool success;
Chilkat.StringBuilder sbPem = new Chilkat.StringBuilder();
sbPem.AppendLine("-----BEGIN RSA PRIVATE KEY-----",true);
sbPem.AppendLine("MIIC .... j5A==",true);
sbPem.AppendLine("-----END RSA PRIVATE KEY-----",true);
success = privKey.LoadPem(sbPem.GetAsString());
if (success != true) {
Debug.WriteLine(privKey.LastErrorText);
return;
}
Chilkat.Rsa rsa = new Chilkat.Rsa();
success = rsa.ImportPrivateKeyObj(privKey);
if (success != true) {
Debug.WriteLine(rsa.LastErrorText);
return;
}
rsa.EncodingMode = "base64";
string strSigned = rsa.OpenSslSignStringENC("12345678");
Debug.WriteLine(strSigned);
string strOriginal = rsa.OpenSslVerifyStringENC(strSigned);
Debug.WriteLine(strOriginal);
|