我有这样的意见:
我想用rsa签名算法签名摘要。 我使用了以下签名技术:
每个人生成并验证签名罚款。但我有3个不同的签名作为输出。 我试过很多次了。而且这些签名不是随机的。我收到3个不同的签名。 怎么会这样?有没有人有这样的问题?我错了什么?
更新
Base64值:
MySigner'签名:
aRiRJgYmFKl8i8 + FTUbr8Ah9sWybNw2XyFLVttaxrWzhj14nRuyL5qSXxaL4 / B0etKZQH5qipZB04wx8 + aoRnnHxNcLFddyxMk7aUmilo + 58k4KyyK43qgyUOmPs6mWvmBHpDf0pcU6FrRiMB543pnYqBZGfmAlfG + Yjjdxbqw4 =
BouncyCastle'签名:
WP1iU2nuooneikMLCaWR9i03B + ISp8 + P + C / OqYHNF0qGioIbaRWCPHhxJqhCJdayr6T / X2XPjE2XebITmSmnd4JQgyECK77ju7AxCgBxIAWvzwDFMrrFvQ05wt8KDiDbcnfrRKZK + CMF / SvyBwBdezGuCQ3mXu7joo5l9LxQrM4 =
Openssl的签名:
LRK / KX / + + 1vUmHLIKNmZy5h84K2ryu9GtfIp2XXeTsJJz96i7tqNg EU / c9KkRhcbf4kFMt / O8HLLp9nNSrm5VafNCrPTmOWJMfRrRZxH1BR8sjqmITTSJOy6kNvkmHcrrwWehcfaBw8ItHp / 2 + m8NY5C / QL4W7hL8qt5KoN3q5E =
更新
带字节的文件
http://download.files.namba.kg/files/5637461
更新
使用BouncyCastle签名摘要的代码
public void SignWithBouncyCastle()
{
byte[] digest = File.ReadAllBytes(@"d:\public\signatures\digest");
byte[] signature = null;
TextReader textReader = new StreamReader(@"e:\PresentCert\RootCATest2.pem"); // file with private key and public key
PemReader pemReader = new PemReader(textReader);
object obj = pemReader.ReadObject();
AsymmetricCipherKeyPair ackp;
ackp = (AsymmetricCipherKeyPair)obj;
RsaDigestSigner signer = new RsaDigestSigner(new Sha1Digest());
signer.Init(true, ackp.Private);
signer.BlockUpdate(digest, 0, digest.Length);
signature = signer.GenerateSignature();
signer.Init(false, ackp.Public);
signer.BlockUpdate(digest, 0, digest.Length);
bool r = signer.VerifySignature(signature);
// r is true
File.WriteAllBytes(@"d:\public\signatures\bouncycastle", signature);
}
然后我使用命令使用openssl验证签名:
openssl rsautl -verify -inkey e:\PresentCert\pubRootCATest2.pem -pubin -in d:\public\signatures\bouncycastle -out verified
比较文件
comp verified d:\public\signatures\bouncycastle
他们是不同的。
更新
更正代码
public void SignMessageWithBouncyCastle()
{
//File.WriteAllBytes(@"c:\msg", Encoding.UTF8.GetBytes("the_secret_message"));
byte[] msg = File.ReadAllBytes(@"c:\msg");
byte[] signature = null;
TextReader textReader = new StreamReader(@"e:\PresentCert\RootCATest2.pem"); // file with private key and public key
PemReader pemReader = new PemReader(textReader);
object obj = pemReader.ReadObject();
AsymmetricCipherKeyPair ackp;
ackp = (AsymmetricCipherKeyPair)obj;
RsaDigestSigner signer = new RsaDigestSigner(new Sha1Digest());
signer.Init(true, ackp.Private);
signer.BlockUpdate(msg, 0, msg.Length);
signature = signer.GenerateSignature();
signer.Init(false, ackp.Public);
signer.BlockUpdate(msg, 0, msg.Length);
bool r = signer.VerifySignature(signature);
// r is true
File.WriteAllBytes(@"c:\bouncycastle", signature);
}
这次我使用了这个openssl命令:
openssl dgst -sha1 -verify c:\pubRootCATest2.pem -signature c:\bouncycastle c:\msg
结果已经验证好了!