How To Create RSA Public and Private Key?
RSA is an algorithm used for Cryptography. It was patented until 2000 in USA (not whole world) where now it can be used freely. RSA has a lot of usage examples but it is mainly used for encryption of small pieces of data like key and Digital signatures. RSA is based integer factorization problem. As it is known that asymmetric ciphers are very slow against symmetric ciphers. So it is used with symmetric cipher like AES to secure bulk data. Using with AES and RSA together named hybrid usage. Here are some practical RSA tools to manage.
In order to manage RSA key we need to create it firstly. we specify the output type where it is file named t1.key and the size of the key with 2048. We used verb
genrsa with OpenSSL. By default keys are created in PEM format as it shown with file command.
$ openssl genrsa -out t1.key 2048
Convert Pem into Der
Formats are used to encode created RSA key and save into a file. Pem is common format but sometime you need to use DER format. Here is how it can be done. We specify input form and output form with inform and outform parameters and than show existing file with in and created file wirh out. Then we check file as we see that data as file typr because of the binary type. Der is not encoded base64 like pem format.
$ openssl rsa -inform pem -outform der -in t1.key -out t1.der
Encrypting RSA Key with AES
Private keys are very sensitive if we transmit it over insecure places we should encrypt it with symmetric keys. Here we use AES with 128 bit key and we set encrypted RSA key file with out parameter. Or while generating the RSA key pair it can be encrypted too.
$ openssl rsa -aes128 -in t1.key -out t1out.pem
List/Show Public Key
A public key in a RSA key pair can be viewed or exported. Below we view with pubout parameter the public key. If we give -out against -text the public key will be written to the file.
$ openssl rsa -in rsa1.pem -pubout -text