public static RSAParameters GetPublicKeyRSAParameters(string publicKeyString) { using (var rsa = RsaPEMHelper.PublicKeyFromPem(publicKeyString)) { return(rsa.ExportParameters(false)); } }
public static bool VerifySignature(string publicKeyString, byte[] hashOfDataToSign, byte[] signature) { using (var rsa = RsaPEMHelper.PublicKeyFromPem(publicKeyString)) { var rsaDeformatter = new RSAPKCS1SignatureDeformatter(rsa); rsaDeformatter.SetHashAlgorithm("SHA256"); return(rsaDeformatter.VerifySignature(hashOfDataToSign, signature)); } }
public static byte[] EncryptData(string publicKeyString, byte[] dataToEncrypt) { byte[] cipherbytes; using (var rsa = RsaPEMHelper.PublicKeyFromPem(publicKeyString)) { cipherbytes = rsa.Encrypt(dataToEncrypt, false); } return(cipherbytes); }