1

我想使用 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>

谢谢!

4

1 回答 1

2
//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>")); 
于 2012-04-24T08:18:51.350 回答