public static RSAParameters GetPrivateKeyRSAParameters(string privateKeyPath) { using (var rsa = RsaPEMHelper.PrivateKeyFromPemFile(privateKeyPath)) { return(rsa.ExportParameters(true)); } }
public static byte[] CreateDigitalSignature(string privateKeyPath, byte[] hashOfDataToSign) { using (var rsa = RsaPEMHelper.PrivateKeyFromPemFile(privateKeyPath)) { var rsaFormatter = new RSAPKCS1SignatureFormatter(rsa); rsaFormatter.SetHashAlgorithm("SHA256"); return(rsaFormatter.CreateSignature(hashOfDataToSign)); } }
public static byte[] DecryptData(string privateKeyPath, byte[] dataToEncrypt) { byte[] plain; using (var rsa = RsaPEMHelper.PrivateKeyFromPemFile(privateKeyPath)) { plain = rsa.Decrypt(dataToEncrypt, false); } return(plain); }