通过OpenSSL(c++)以XML(w3c)格式保存RSA公钥和私钥
Save RSA public and private keys in XML (w3c) format via OpenSSL (c++)
我想使用RSA公钥和私钥的XML文件格式。现在我找到了如何以 PEM 和二进制 (DER) 格式保存这些密钥(例如,PEM_write_RSAPrivateKey())
我有一个带有xml格式RSA密钥的字符串,我需要将它们加载到EVP_PKEY或RSA OpenSSL结构中。
XML 格式如下所示:
<RSAKeyPair>
<Modulus>...</Modulus>
<Exponent>...</Exponent>
<P>...</P>
<Q>...</Q>
<DP>...</DP>
<DQ>...</DQ>
<InverseQ>
...
</InverseQ>
<D>...</D>
</RSAKeyPair>
谢谢!
//just a code for demo,not for actually use
int len;
RSA *rsa;
BIO *bio;
unsigned char *data;
bio = BIO_new(BIO_s_meme());
BIO *b64;
b64 = BIO_new(BIO_f_base64());
BIO_write(bio, "<RSAKeyPair>n",strlen("<RSAKeyPair>n"));
//write Modulus
len=BN_num_bytes(rsa->n);
data=(unsigned char *)OPENSSL_malloc(len);
if(data) {
BIO_write(bio," <Modulus>",strlen(" <Modulus>"));
BN_bn2bin(rsa->n,data);
bio = BIO_push(b64, bio);
BIO_write(bio, data, len);
(void)BIO_flush(bio);
BIO_pop(bio);
BIO_reset(b64);
BIO_write(bio,"</Modulus>",strlen("</Modulus>"));
}
//write Exp
...
//write the bignum in rsa structure you want
BIO_write(bio, "</RSAKeyPair>n",strlen("</RSAKeyPair>"));
相关文章:
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- 将字符指针十六进制转换为字符串并保存在文本文件C++中
- SSH通过/sbin/SSH无法读取RSA密钥文件(从控制台运行)
- 如何使用Crypto++并为RSA返回可打印的字节/字符数组
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- EvtExportLogneneneba API正在将远程计算机的事件日志保存到远程PC本身.如何将其保存到主机
- 在C++中将类(带有Vector成员)保存为二进制文件
- C++.我想将更改后的特定字符行保存在字符串中
- 使用FFMPEG将RGB图像序列保存到.mp4时出现问题
- 将RGB图像保存为PPM格式
- 哈希文件递归并保存到矢量Cryptopp中
- 如何将二进制格式的 C++ 对象的 std::vector 保存到磁盘?
- 无法通过头文件保存变量的值
- 我们可以将数据永久保存为数据结构吗?
- 我的程序有一个保存配置文件的GUI,如何双击此配置文件以直接加载带有配置数据的GUI?
- 保存/加载大量短数组到二进制文件
- 计算 RSA 并以十六进制格式保存到文件
- 通过OpenSSL(c++)以XML(w3c)格式保存RSA公钥和私钥