小编Thu*_*uan的帖子

SHA256签名在.NET 4.5中停止运行

我们有一段代码创建了一个SigningCredentials对象,用于使用SHA256算法对xml文档进行签名.它完美适用于.NET 3.5.但是,当我们将代码库升级到.NET 4.5时,它会停止工作.相同的代码,相同的证书!我花了好几个小时在互联网上调试和搜索,没有任何运气.

谁能告诉我这里的问题是什么?先感谢您.

创建SigningCredentials的代码:

public SigningCredentials CreateSigningCredentials(X509Certificate2 cert)
{
    var ski = new SecurityKeyIdentifier(new X509RawDataKeyIdentifierClause(cert));
    return new SigningCredentials(new X509AsymmetricSecurityKey(cert), "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256", "http://www.w3.org/2001/04/xmlenc#sha256", ski);
}
Run Code Online (Sandbox Code Playgroud)

例外:

[CryptographicException: Invalid algorithm specified.
]
   System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) +41
   System.Security.Cryptography.Utils.SignValue(SafeKeyHandle hKey, Int32 keyNumber, Int32 calgKey, Int32 calgHash, Byte[] hash, Int32 cbHash, ObjectHandleOnStack retSignature) +0
   System.Security.Cryptography.Utils.SignValue(SafeKeyHandle hKey, Int32 keyNumber, Int32 calgKey, Int32 calgHash, Byte[] hash) +118
   System.Security.Cryptography.RSACryptoServiceProvider.SignHash(Byte[] rgbHash, Int32 calgHash) +334
   System.Security.Cryptography.RSAPKCS1SignatureFormatter.CreateSignature(Byte[] rgbHash) +321
   System.IdentityModel.SignedXml.ComputeSignature(HashAlgorithm hash, AsymmetricSignatureFormatter formatter, String signatureMethod) +323
   System.IdentityModel.SignedXml.ComputeSignature(SecurityKey signingKey) +690
   System.IdentityModel.EnvelopedSignatureWriter.ComputeSignature() +338
   System.IdentityModel.EnvelopedSignatureWriter.OnEndRootElement() …
Run Code Online (Sandbox Code Playgroud)

.net signing certificate sha256 wif

17
推荐指数
2
解决办法
8990
查看次数

标签 统计

.net ×1

certificate ×1

sha256 ×1

signing ×1

wif ×1