我是密码学新手,所以也许我对这里应该发生的事情感到困惑。我从 32 字节消息摘要开始,并尝试使用我的私钥对其进行签名。 RSA.SignHash 的输出是 128 字节。我预计 32。
static private byte[] RSAHashAndSignData(byte[] data, RSAParameters privateKey)
{
byte[] signedHash;
//Create a new instance of RSACryptoServiceProvider.
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{
//Import the public key
RSA.ImportParameters(privateKey);
//Encrypt the passed byte array
var sha = SHA256Managed.Create();
var digest = sha.ComputeHash(data);
signedHash = RSA.SignHash(digest, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
}
return signedHash;
}
最佳答案
I am expecting 32.
这是一个错误的假设。签名不会产生等于输入大小的大小。
使用 PKCS#1 填充,使用 1024 位 RSA key 将生成 128 字节签名。签名的大小与签名 key 的模数的大小有关。
关于c# - SHA256 的 RSACryptoServiceProvider.SignHash 返回 128 字节而不是 32?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45927543/