.net SHA256WithRSA 加密

最近公司用到了SHA256WithRSA方式,以前一直是SHA1WithRSA,写下来记录下。搜了很久没搜到

 //SHA256WithRSA
X509Certificate2 privateCert = new X509Certificate2(pfxFilePath, pfxPassword, X509KeyStorageFlags.Exportable);            
RSACryptoServiceProvider privateKey = (RSACryptoServiceProvider)privateCert.PrivateKey;
// This one can:
RSACryptoServiceProvider privateKey1 = new RSACryptoServiceProvider();
privateKey1.ImportParameters(privateKey.ExportParameters(true));
byte[] data = Encoding.UTF8.GetBytes("加密前明文");
byte[] signature = privateKey1.SignData(data, "SHA256");
//密文
string sign=Convert.ToBase64String(signature);



你可能感兴趣的:(asp.net)