【发布时间】:2015-09-10 14:24:32
【问题描述】:
如here 所述,消息签名的长度等于私钥的模数,又名公钥。
我正在实施一个对消息进行签名的系统,但我遇到了无法解决的大小不匹配问题。
我用crypto++。
这是我使用的代码:
/* Create RSA Keys */
RSA::PrivateKey privateKey;
privateKey.GenerateRandomWithKeySize(prng, 3072);
RSA::PublicKey publicKey(privateKey);
cout << ">> RSA Keys generated";
/* Key Size */
string spki;
StringSink sSink(spki);
publicKey.Save(sSink);
cout <<" ("<< spki.size()<<" bytes)"<<endl;
RSASSA_PKCS1v15_SHA_Signer signer(privateKey);
size_t length = signer.MaxSignatureLength();
cout <<"MaxSignatureLength " <<length<<endl;
SecByteBlock signature( length );
输出是:
>> RSA Keys generated (420 bytes)
>> ServerHello sent (436 bytes)
MaxSignatureLength 384
RSA Signature length 384
MaxSignatureLength 和 RSA Signature length 不应该是 420 字节长吗?
是我使用的算法有问题吗?
【问题讨论】:
-
我对加密和加密算法编程不太熟悉,但是当我做一些研究时,我发现这个网站可以为您提供一些帮助。 cryptopp.com/docs/ref/index.html
-
@Eisen - 相关,我认为您正在将原始字节传递给
Crafter,如果您有一条跨越多个在线(或超过- the-air) 第 1 层帧。你看过Protocol Buffers吗?我认为您可以使用它们在Crafter中构建消息。或者,您可以 ASN.1 对您的消息进行编码。或者,您可以使用BSON之类的内容。在所有这些情况下,您将知道您发送和接收的消息的长度。
标签: c++ rsa digital-signature crypto++