1

我正在使用 Crypto++ 实现 RSA。我正在尝试生成一对 RSA 密钥(公共和私有)来像这样归档。

当我把所有的东西都放进去时,代码可以完美运行main。当我尝试将其拆分为函数并将AutoSeededRandomPool对象作为参数传递时,如下所示:

int generateKeyToFile(
    AutoSeededRandomPool rnd, 
    string publicKeyFileName, string privateKeyFileName){
    try
    {
        RSA::PrivateKey rsaPrivate;
        rsaPrivate.GenerateRandomWithKeySize(rnd, 3072);

        RSA::PublicKey rsaPublic(rsaPrivate);
        EncodePrivateKey(privateKeyFileName, rsaPrivate);
        EncodePublicKey(publicKeyFileName, rsaPublic);

        cout << "Successfully generated and saved RSA keys" << endl;
        return 1;
    }

    catch (CryptoPP::Exception& e)
    {
        cerr << e.what() << endl;
        return -1;
    }
}

在构建项目时,我收到了错误:

错误 C2719: 'rnd': 带有 __declspec(align('8')) 的形式参数不会对齐

我无法从 Google 找到与此错误相关的与 Crypto++ 相关的确切结果,但我找到了错误代码 C2719的一些结果。其内容:

'parameter': 带有 __declspec(align('#')) 的形参不会对齐

函数参数上不允许使用 align __declspec 修饰符。函数参数对齐由使用的调用约定控制。有关详细信息,请参阅调用约定。

以下示例生成 C2719 并显示如何修复它:

// C2719.cpp  
void func(int __declspec(align(32)) i);   // C2719  
// try the following line instead  
 void func(int i);

我还没有从中得到任何想法,将这个“解决方案”应用到我的案例中。

好像AutoSeededRandomPool不能作为参数传递。有没有办法解决这个问题?

4

1 回答 1

1
int generateKeyToFile(
     AutoSeededRandomPool rnd, 
    string publicKeyFileName, string privateKeyFileName){
    ...
}

使用参考:

int GenerateKeyToFile(
    RandomNumberGenerator& rnd, 
    const string& publicKeyFileName,
    const string& privateKeyFileName)
    {
        ...
    }

我不确定AutoSeededRandomPool是否可以复制。我认为事情正在按预期工作,因为您可能不应该复制一个。只需通过引用或指针传递它。

于 2016-11-16T19:41:56.730 回答