Created
February 19, 2022 18:55
-
-
Save rabieedev1996/e6e1783a6a19b0ded358c79e053cbdf7 to your computer and use it in GitHub Desktop.
Rsa verify sign
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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