2
我是密码学的新手,所以也许我对这里会发生什么感到困惑。我从一个32字节的消息摘要开始,并尝试使用我的私钥对其进行签名。 RSA.SignHash的输出是128字节。我期待着32RSACryptoServiceProvider.SignHash与SHA256返回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;
}
谢谢,这使得吨感。 –
准确地说,签名的大小与字节的模数完全相同,不管填充如何(除了可能用于教科书RSA,其中输出是小于模数的数字,而不是八位字符串)。根据定义,模数与RSA的密钥大小相同。 –
如果您有选择,也请使用RSA-2048或更高版本。行业已经从1024位密钥转移。 – vcsjones