我是密码技术的新手,所以也许我对这里应该发生的事情感到困惑。我从一个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;
}
Run Code Online (Sandbox Code Playgroud)