vendredi 24 janvier 2020

How can I convert OpenSSH public key into OpenSSL in Ruby (or Rails)

I have public keys in a database and need them to validate JWT tokens. The keys are in OpenSSH public key format, so I need to convert them into PEM format like this:

-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEAx9jNrkPwjH12qVhmpKs/MLfvsYy5uob+jx68Mdsv5tmZG5HVq6nm
sYKkcDdwLseShWREIOmB0lC/bhaaihuAvs4ZZcDRKnrq2FX+WQz9/mHScr1kQTgB
adRdQWzG3KXeOJJiKSBfNHVn3Iixdba/IX5rYhARbDMqPQfwz08gKHbFLuNogNN0
hm5yTFQU1z0bhR87dHFJgfwQSVloeNKTsXleoGZqGBNbjMdF0HOEvQaWzenQHJde
dTaF39Ok6q0k4QsSHyuzmoXy30O3oe31D7mu4QQOk/Lj61zVZrR25YvGYpn0ym+d
cWxKFyeVX/McstRhu7wD1iu0kj74A2VhrwIDAQAB
-----END RSA PUBLIC KEY-----

Is there a way to convert a OpenSSH public key into a OpenSSL one with Ruby (not with openssl)?

I already found this: https://gist.github.com/tombh/f66de84fd3a63e670ad9 But unfortunately it's throwing an error in recent Ruby versions.

I also found the SSHKey gem but that doesn't seem to offer that functionality.

Aucun commentaire:

Enregistrer un commentaire