我需要带有证书的签名数据。我的签名方法:
private static string CreateSignature(string signatureString)
{
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
X509Certificate2 cert = new X509Certificate2(HttpContext.Current.Server.MapPath("~/eCommerceConnectCrfs/test-server.cert"), "password");
RSACryptoServiceProvider rsaCryptoIPT = (RSACryptoServiceProvider)cert.PrivateKey;
ASCIIEncoding encoder = new ASCIIEncoding();
byte[] binData = encoder.GetBytes(signatureString);
byte[] binSignature = rsaCryptoIPT.SignData(binData, sha1);
return Convert.ToBase64String(binSignature);
}
但字段 cert.PrivateKey 为 NULL。我有带有私钥的 *.pem 文件,但我不知道如何使用它。请帮助获得签名!