为什么在使用RSA签名时使用SHA256和无效的哈希算法? [英] Why is SHA256 and invalid hash algorithm when signing with RSA?

查看:922
本文介绍了为什么在使用RSA签名时使用SHA256和无效的哈希算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下方法对流进行签名,但是我总是收到一个加密异常,即使该文档中列出了它,它也不是有效的哈希算法:

I am trying to sign a stream using the method below but I always get a Cryptographic Exception saying that it is not a valid hash algorithm even though it is listed in the documentation:

byte[] SignData(RSACryptoServiceProvider rsa, Stream stream, string hashName)
{
    HashAlgorithm hash = HashAlgorithm.Create(hashName);
    byte[] signature = rsa.SignData(stream, hash);
    return signature;
}

我使用"SHA256"作为hashName参数来调用它.并且在调用rsa.SignData()的行上引发了异常.

I am calling it with "SHA256" as the hashName parameter. and the exception is thrown at the line where rsa.SignData() is called.

这不是使用X509证书,不是重复的.顺便说一句,请参阅下面的答案.

This is NOT using X509 certificates, it is not a duplicate. BTW see answer below.

推荐答案

只需解决,并且它不是重复的,因为我使用的是.NET的普通 RSACryptoServiceProvider 和不是X509证书.

Just resolved and it is not a duplicate because I am using the plain RSACryptoServiceProvider of .NET and not X509 certificates.

我遇到了这个帖子: http://hintdesk.com/c-how-to-fix-invalid-algorithm-specified-when-signing-with-sha256/

I ran into this post: http://hintdesk.com/c-how-to-fix-invalid-algorithm-specified-when-signing-with-sha256/

在阅读它时,我想到要检查一下RSA SignatureAlgorithm,它得到的URI表明它是 SHA1 ,因此没有SHA256或SHA512.然后我在MSDN文档中查询了该属性,并说该属性总是返回该值,因为它仅支持该值,因此仅 SHA1 .

Reading it it occurred to me to to examine the RSA SignatureAlgorithm and it the resulting URI indicated it was SHA1 so no SHA256 or SHA512. Then I looked up that property in MSDN documentation and it says that property always returns that value because it only supports that, so only SHA1.

这篇关于为什么在使用RSA签名时使用SHA256和无效的哈希算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆