【发布时间】:2018-12-12 02:42:55
【问题描述】:
在使用 RSA 加密后,我正在尝试将 RSA 私钥导出到文件。 到目前为止,我尝试使用 2 种方法导出它:
int main()
{
AutoSeededRandomPool rnd;
const std::string publickey_str =
"-----BEGIN PUBLIC KEY-----\n"
"rsa public key there\n"
"-----END PUBLIC KEY-----";
RSA::PublicKey master_publicKey;
StringSource source(publickey_str, true);
PEM_Load(source, master_publicKey);
CryptoPP::RSAES_OAEP_SHA_Encryptor e(master_publicKey);
InvertibleRSAFunction params;
params.GenerateRandomWithKeySize(rnd, 4096);
RSA::PrivateKey privateKey(params);
FileSink file("exported.bin")
//Method 1
FileSink file("exported.bin")
ArraySource export_private_key(privateKey, sizeof(privateKey),true, AuthenticatedEncryptionFilter(e, new Redirector(file))); //can't find a way to convert privateKey to a valid type for ArraySource
//Method 2
privateKey.Save( new AuthenticatedEncryptionFilter(e, new Redirector(file))); //doesn't work, as Save() expects BufferedTransformation
有没有什么方法可以使用这两种方法中的一种来实现我的目标,或者我必须将我的私钥转换为另一种格式(BER 或 PEM 编码),然后再对其应用 RSA?
提前致谢
P.S:我的问题是特定于 Windows 的,如果它有任何影响的话。
【问题讨论】:
-
下载PEM Pack并用它来密码保护磁盘上的私钥。另外(如果我正确地解析了事情)......如果你用它的公钥加密私钥,那么你可能无法使用密钥来解密自己,因为私钥在解密。
标签: c++ windows encryption crypto++