[英]Digital sign From SHA1 to SHA256
I'm trying to update a function that performs a digital signature, I want to switch from SHA1 SHA256 this is the current function: 我正在尝试更新执行数字签名的功能,我想从SHA1切换到SHA256,这是当前功能:
private byte[] zSignData(Byte[] msg, X509Certificate2 signerCert)
{
ContentInfo contentInfo = new ContentInfo(msg);
SignedCms signedCms = new SignedCms(contentInfo, false);
CmsSigner cmsSigner = new CmsSigner(signerCert);
cmsSigner.DigestAlgorithm = new Oid("1.3.14.3.2.26"); //SHA1
signedCms.ComputeSignature(cmsSigner, false);
return signedCms.Encode();
}
this function work well 这个功能很好用
To update to SHA256, I changed 为了更新为SHA256,我更改了
cmsSigner.DigestAlgorithm = new Oid("1.3.14.3.2.26"); //SHA1
with 同
cmsSigner.DigestAlgorithm = new Oid("2.16.840.1.101.3.4.2.1");//SHA256
but at 但是在
signedCms.ComputeSignature(cmsSigner, false);
I get the following exception 我得到以下异常
System.Security.Cryptography.CryptographicException Message=There was an internal error. System.Security.Cryptography.CryptographicException Message =存在内部错误。
Someone has a suggestion? 有人有建议吗?
I work with VS2010 Professional 64 and win7 professional 64 我使用VS2010 Professional 64和Win7 Professional 64
i believe there is a typo bug in CAPIBase: 我相信CAPIBase中有一个拼写错误:
internal const string szOID_OIWSEC_SHA256 = "2.16.840.1.101.3.4.1";
internal const string szOID_OIWSEC_SHA384 = "2.16.840.1.101.3.4.2";
internal const string szOID_OIWSEC_SHA512 = "2.16.840.1.101.3.4.3";
should be: 应该:
internal const string szOID_OIWSEC_SHA256 = "2.16.840.1.101.3.4.2.1";
internal const string szOID_OIWSEC_SHA384 = "2.16.840.1.101.3.4.2.2";
internal const string szOID_OIWSEC_SHA512 = "2.16.840.1.101.3.4.2.3";
more discussion on this is here: 关于此的更多讨论在这里:
blogs.msdn.com/b/alejacma/archive/2012/08/02/10018922.aspx blogs.msdn.com/b/alejacma/archive/2012/08/02/10018922.aspx
Todd, what makes you believe that OID 2.16.840.1.101.3.4.2.1 is not SHA256? Todd,是什么让您相信OID 2.16.840.1.101.3.4.2.1不是SHA256? What is the correct OID then? 那么正确的OID是什么?
You are specifying the wrong OID -that OID is for NULL signed blobs. 您指定的OID错误-该OID用于NULL签名的Blob。 For an RSA signed blob, you need to use 1.2.840.113549.1.1.5 sha1RSA. 对于RSA签名的Blob,您需要使用1.2.840.113549.1.1.5 sha1RSA。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.