使用 CryptoPP::RSA 时无法将 AutoSeededRandomPool 作为参数传递,错误 C2729
Cannot pass AutoSeededRandomPool as parameter when using CryptoPP::RSA, error C2729
我正在使用 Crypto++ 实现 RSA。我正在尝试生成一对 RSA 密钥(public 和私有)来像这样归档。
当我全部放入 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;
}
}
构建项目时出现错误:
error C2719: 'rnd': formal parameter with __declspec(align('8')) won't
be aligned
我无法从 Google 中找到此错误的确切 Crypto++ 相关结果,但我找到了 error code C2719 的一些结果。其内容:
'parameter': formal parameter with __declspec(align('#')) won't be
aligned
The align __declspec modifier is not permitted on function parameters.
Function parameter alignment is controlled by the calling convention
used. For more information, see Calling Conventions.
The following sample generates C2719 and shows how to fix it:
// C2719.cpp
void func(int __declspec(align(32)) i); // C2719
// try the following line instead
void func(int i);
我还没有从中得到任何想法将这个 "solution" 应用到我的案例中。
似乎 AutoSeededRandomPool
不能作为参数传递。有办法解决这个问题吗?
int generateKeyToFile(
AutoSeededRandomPool rnd,
string publicKeyFileName, string privateKeyFileName){
...
}
使用参考:
int GenerateKeyToFile(
RandomNumberGenerator& rnd,
const string& publicKeyFileName,
const string& privateKeyFileName)
{
...
}
我不确定 AutoSeededRandomPool
是否可复制构造。我认为事情正在按预期进行,因为您可能不应该复制一个。只需通过引用或指针传递即可。
我正在使用 Crypto++ 实现 RSA。我正在尝试生成一对 RSA 密钥(public 和私有)来像这样归档。
当我全部放入 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;
}
}
构建项目时出现错误:
error C2719: 'rnd': formal parameter with __declspec(align('8')) won't be aligned
我无法从 Google 中找到此错误的确切 Crypto++ 相关结果,但我找到了 error code C2719 的一些结果。其内容:
'parameter': formal parameter with __declspec(align('#')) won't be aligned
The align __declspec modifier is not permitted on function parameters. Function parameter alignment is controlled by the calling convention used. For more information, see Calling Conventions.
The following sample generates C2719 and shows how to fix it:
// C2719.cpp void func(int __declspec(align(32)) i); // C2719 // try the following line instead void func(int i);
我还没有从中得到任何想法将这个 "solution" 应用到我的案例中。
似乎 AutoSeededRandomPool
不能作为参数传递。有办法解决这个问题吗?
int generateKeyToFile(
AutoSeededRandomPool rnd,
string publicKeyFileName, string privateKeyFileName){
...
}
使用参考:
int GenerateKeyToFile(
RandomNumberGenerator& rnd,
const string& publicKeyFileName,
const string& privateKeyFileName)
{
...
}
我不确定 AutoSeededRandomPool
是否可复制构造。我认为事情正在按预期进行,因为您可能不应该复制一个。只需通过引用或指针传递即可。