如何使用aes键创建.pem文件 [英] How to create a .pem file with aes key

查看:257
本文介绍了如何使用aes键创建.pem文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须创建一个aes-256密钥并将其存储在.pem文件中。我正在使用 RAND_bytes()来简单地创建256位随机密钥。之后,我如何将其保存到pem文件。
我查看了阅读和在C 中将rsa键写入pem文件,然后将 openssl pem 。但是我没有使用RSA密钥。

i have to create an aes-256 key and store it in a .pem file. I am using RAND_bytes() to simply create a 256 bit random key. After this how can i save this to a pem file. I have looked at Reading and writing rsa keys to a pem file in C and openssl pem. But i am not working with RSA keys.

我怀疑我的任务比从base64创建pem ,但没有太多的帮助。

I suspect my task is much simpler like create pem from base64 but not much help.

PS:此密钥将用于加密自签名数字证书。

PS: This key will be used to encrypt a self signed digital certificate.

编辑:查看更多我发现我可以使用bio来隐藏pem ,像 PEM_write_bio_PrivateKey ,但它需要使用EVP_PKEY格式作为参数。那么如何将char buf转换成EVP_PKEY。我发现d2i_PublicKey,但它涉及RSA,我不确定RSA如何适应这里的图片。

looking around more i found that i could use bio to covert to pem, something likePEM_write_bio_PrivateKey but it takes EVP_PKEY format as argument. So how can i convert char buf to EVP_PKEY. i found d2i_PublicKey but it involves RSA and am unsure how RSA would fit into picture here.

推荐答案

您可以使用BouncyCastle库的PEMWriter类将aes键转换为.pem。

You can convert aes key to .pem by using PEMWriter class of bouncyCastle library.

http://www.bouncycastle.org/documentation.html

这篇关于如何使用aes键创建.pem文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆