Skip to content

Instantly share code, notes, and snippets.

@rabieedev1996
Created February 19, 2022 18:55
Show Gist options
  • Save rabieedev1996/e6e1783a6a19b0ded358c79e053cbdf7 to your computer and use it in GitHub Desktop.
Save rabieedev1996/e6e1783a6a19b0ded358c79e053cbdf7 to your computer and use it in GitHub Desktop.
Rsa verify sign
public static bool VerifySign(string inputText, string signedMessage, string publicKey)
{
bool success = false;
using (var rsa = new RSACryptoServiceProvider())
{
byte[] bytesToVerify = Encoding.UTF8.GetBytes(inputText);
byte[] signedBytes = Convert.FromBase64String(signedMessage);
try
{
rsa.FromXmlString(publicKey);
SHA256Managed Hash = new SHA256Managed();
byte[] hashedData = Hash.ComputeHash(signedBytes);
success = rsa.VerifyData(bytesToVerify, CryptoConfig.MapNameToOID("SHA256"), signedBytes);
}
catch (CryptographicException e)
{
Console.WriteLine(e.Message);
}
finally
{
rsa.PersistKeyInCsp = false;
}
}
return success;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment