Sign with the private key using the SHA-256 algorithm
Salvatore Rizzo
21
Reputation points
Hi all, I have to implement the signing of a string with the private key using the SHA-256 algorithm.
I am developing MyPos bank online checkout, here are the specs.
Starting from the certificate I extrapolated the private key but I can't sign the string, I get object not found in the RSA.SignData line.
I use a 4.5.1 webforms project
public static string Encrypt(string message, string certificate)
{
X509Certificate2 cert = new X509Certificate2(UTF8Encoding.UTF8.GetBytes(certificate));
RSACryptoServiceProvider RSA = (RSACryptoServiceProvider)cert.PrivateKey;
var bytesToDecrypt = Convert.FromBase64String(message); // string to decrypt, base64 encoded
byte[] encryptedData = RSA.SignData(bytesToDecrypt, "SHA256");
return Convert.ToBase64String(encryptedData);
}
Developer technologies | ASP.NET | Other
3,600 questions
Sign in to answer