How to create a .pem file with aes key

会有一股神秘感。 提交于 2019-12-13 01:43:17

问题


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.

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

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

EDIT: 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.


回答1:


AES key is just a random byte array. You can simple store the bytes in a file without any structure.




回答2:


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

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



来源:https://stackoverflow.com/questions/35681704/how-to-create-a-pem-file-with-aes-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!