I'm trying to generate a private key and public key pair. I want to use the private key to sign my JWT and send the public key to a 3rd party to decode my JWT.
On my mac os terminal, I generated my keys like this:
ssh-keygen -m PEM -t rsa -b 2048
Do now I've pkey & pkey.pub as private and public keys respectively. Now in my rails console I tried to get the private key like this, which works fine:
rsa_private = OpenSSL::PKey::RSA.new(File.read("/path/to/private/key/pkey"))
rsa_private.to_s
"-----BEGIN RSA PRIVATE KEY-----\nCONTENTS_OF_PKEY_FILE\n-----END RSA PRIVATE KEY-----\n"
Now in rails, I can get the public key from generated private key like this :
pub_key = rsa_private.public_key
But when I try to print it's contents, it differs from what's there in pkey.pub generated when I ran ssh-keygen command.
pub_key looks something like this:
"-----BEGIN PUBLIC KEY-----\nSOME_CONTENT\n-----END PUBLIC KEY-----\n"
But my pkey.pub file looks different, something like this:
ssh-rsa SOME_OTHER_CONTENT [email protected]
So, my question, is how can I get 2 different public keys for same private key? Which one do I use to decode my JWT?