小编Eis*_*eim的帖子

RSA签名大小不匹配

如前所述这里,消息签名的长度等于私钥的模数,又称公钥.

我正在实现一个签署消息的系统,而且我的大小不匹配是我无法解决的.我用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字节长?

我使用的算法有问题吗?

c++ rsa digital-signature crypto++

5
推荐指数
1
解决办法
468
查看次数

如何将 SecByteBlock 转换为字符串?

我在尝试转换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)

上面的代码应该是:

  1. 从文件加载密钥;

  2. 创建四;

  3. 加密(AES)用户访问数据;

  4. 将iv与加密的用户数据访问连接起来,创建一个“令牌”;

多次运行测试,有时(1 到 10 次)std::string(iv.begin(), iv.end())无法正常工作。iv 中似乎有一个“换行符”,导致转换失败。

我尝试了很多东西,但没有任何效果,而且我没有使用 C++ 的经验。

我希望有人可以帮助我。

c++ security aes crypto++

4
推荐指数
1
解决办法
3566
查看次数

UTC 时间戳比较

我正在开发一个客户端-服务器自定义应用程序(将在 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)

c++ linux timestamp utc localtime

1
推荐指数
1
解决办法
2415
查看次数

标签 统计

c++ ×3

crypto++ ×2

aes ×1

digital-signature ×1

linux ×1

localtime ×1

rsa ×1

security ×1

timestamp ×1

utc ×1