Create RSA public / private key with OpenSSL?
The main problem is that I am fairly new to C and the OpenSSL documentation is not clear enough for me, I tried to use Reading and writing rsa keys to a pem file in C , but I don't quite understand it. For example, how create_rsa_key()
does a function create both private and public? And where does it come from pCipher
? And what is the point pcszPassphrase
?
I'll explain that this is some kind of pseudocode, this is what I want to do, and the ones in bold are the ones I don't know how to do:
- generate private key and public key as buffers in hex (client)
- it is safe (public) to publish the key to another endpoint
- encrypt some data with a random 256-bit password using AES256 CBC (server)
- encrypt password with public key (server)
- send encrypted data to client (server)
- decrypt encrypted 256-bit password with private key (client)
- decrypt file
Basically I know how to handle AES encryption / decryption and communication protocol, they are already implemented anyway, my problem is RSA and I need not base64 or pem hex as I work with sockets and also send and store as binary data.
source to share
As discussed on IRC, the answer to the create_rsa_key question is at fooobar.com/questions/374811 / ... - it is not designed to work that way.
pcszPassphrase stands for a password / passphrase to protect a private key. It will be provided by the user, but this is not a requirement.
source to share