I generate the private key
openssl genrsa -out private_key.pem 2048
Then I generate the public key from the private key
openssl rsa -in private_key.pem -out public_key.pem -outform PEM -pubout
I would like to hard-code these keys into my java program. And I want to use it with the PrivateKey
and PublicKey
classes in java.
My initial thought is I have to base64 encode the .pem files. Then there must be some java methods to convert the base64 encoded keys to their respective PrivateKey
and PublicKey
classes.
Thoughts?
Openssl CLI does have the base64 encode command but ....
There's the usual:
-----BEGIN PUBLIC KEY-----
keyinfo
-----END PUBLIC KEY-----
Do I need to parse these away before doing the base64 encode?