C# 使用X509Certificate对pdf by.cer文件进行数字签名时获取错误No Private Key
我使用带有X509证书的.cer文件对pdf进行数字签名。但是在外部签名上我没有得到签名。错误来自“无私钥” 这是我的密码C# 使用X509Certificate对pdf by.cer文件进行数字签名时获取错误No Private Key,c#,asp.net,certificate,x509certificate,x509certificate2,C#,Asp.net,Certificate,X509certificate,X509certificate2,我使用带有X509证书的.cer文件对pdf进行数字签名。但是在外部签名上我没有得到签名。错误来自“无私钥” 这是我的密码 string uc= Server.MapPath("~/username.cer"); System.Security.Cryptography.X509Certificates.X509Certificate cert = new System.Security.Cryptography.X509Certificates.X509Certificate(); cert.
string uc= Server.MapPath("~/username.cer");
System.Security.Cryptography.X509Certificates.X509Certificate cert = new System.Security.Cryptography.X509Certificates.X509Certificate();
cert.Import(uc);
X509Certificate2 signatureCert = new X509Certificate2(cert);
IExternalSignature externalSignature = new X509Certificate2Signature(signatureCert, "SHA-1");
在最后一行我得到错误“没有私钥”
建议我解决方案
.cer
文件不包含私钥,它只包含X.509证书的公共部分。建议解决方案?获取带有私钥的证书。如果它是一个文件,则通常具有.pfx
或.p12
文件扩展名。@Crypt32谢谢您的回复。任何一个例子都建议我使用.pfx文件在pdf上签名,使用#x509certificate2或#PKCS11i我猜代码是一样的,只是文件应该是.pfx而不是.cer