如前所述这里,消息签名的长度等于私钥的模数,又称公钥.
我正在实现一个签署消息的系统,而且我的大小不匹配是我无法解决的.我用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 );
Run Code Online (Sandbox Code Playgroud)
输出是:
>> RSA Keys generated (420 bytes)
>> ServerHello sent (436 bytes)
MaxSignatureLength 384
RSA Signature length 384
Run Code Online (Sandbox Code Playgroud)
不应该MaxSignatureLength,和RSA Signature length420字节长?
我使用的算法有问题吗?
我在尝试转换SecByteBlock为字符串时遇到问题。这是我的情况:
我想使用带有静态密钥和动态 iv 的 AES 加密用户访问数据。我的代码是这样的:
AesKeyIvFactory aesKeyIvFactory;
SecByteBlock key = aesKeyIvFactory.loadKey();
SecByteBlock iv = aesKeyIvFactory.createIv();
encryptionService->encode(&userAccess, key, iv);
std::string token = std::string(iv.begin(), iv.end()) + userAccess;
Run Code Online (Sandbox Code Playgroud)
上面的代码应该是:
从文件加载密钥;
创建四;
加密(AES)用户访问数据;
将iv与加密的用户数据访问连接起来,创建一个“令牌”;
多次运行测试,有时(1 到 10 次)std::string(iv.begin(), iv.end())无法正常工作。iv 中似乎有一个“换行符”,导致转换失败。
我尝试了很多东西,但没有任何效果,而且我没有使用 C++ 的经验。
我希望有人可以帮助我。
我正在开发一个客户端-服务器自定义应用程序(将在 linux 上运行),我发送的其中一个帧包含时间戳(即发送帧的时间)。
为了使我的应用程序可靠,我曾经gmtime在客户端上生成时间。我在比利时,所以现在客户端 VM 的时间比 UTC 时间晚 2 小时(因为夏季时间)。
在服务器端,我首先将接收到的字符串转换为time_t类型。我这样做是为了使用该difftime函数来查看时间戳是否太旧。然后,我再次使用 生成时间戳(UTC 时间)gmtime,并将其转换为time_t.
然后我比较两者time_t以查看时差。
我在服务器端转换时间时遇到问题。我使用与客户端相同的代码,但输出gmtime不同...
客户端:生成时间戳的函数,并将其导出为字符串 ( time_str):
std::string getTime()
{
time_t rawtime;
struct tm * timeinfo;
char buffer[80];
time (&rawtime); // Get time of the system
timeinfo = gmtime(&rawtime); // Convert it to UTC time
strftime(buffer,80,"%d-%m-%Y %H:%M:%S",timeinfo);
std::string time_str(buffer); // Cast it into a string
cout<<"Time Stamp now (client) : "<<time_str<<endl;
return …Run Code Online (Sandbox Code Playgroud)