How to create a .pem file with aes key

I need to create the aes-256 key and save it in a .pem file. I use RAND_bytes() to easily create a 256-bit random key. After that, how can I save this to a pem file. I looked at Reading and writing rsa keys to a pem file in C and openssl pem . But I do not work with RSA keys.

I suspect that my task is much simpler than creating a pem from base64 , but it doesn't help much.

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

EDIT: Looking back more, I found that I could use a biography for hidden until pem, something like PEM_write_bio_PrivateKey , but the EVP_PKEY format is used as an argument. So how can I convert char buf to EVP_PKEY. I found d2i_PublicKey, but it includes RSA and is not sure how RSA will fit in the picture here.

0
source share
2 answers

AES is just a random array of bytes. You can just store bytes in a file without any structure.

0
source

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

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

0
source

Source: https://habr.com/ru/post/885409/


All Articles