I have an RSA public key modulus and exponent string.
I want to create a OpenSSL::PKey::RSA
from these two strings.
Basically they come in as:
- n = 'long string'
- e = '4-character string'
How would I do this in Ruby? The end goal is to get this to the JWT gem.
Update
I'm currently in Ruby 2.3.1, so this works:
key = OpenSSL::PKey::RSA.new
key.e = OpenSSL::BN.new(Base64.decode64(e), 2)
key.n = OpenSSL::BN.new(Base64.decode64(n), 2)
However, it won't work during an upgrade.
Base64.urlsafe_decode64
instead ofBase64.decode64
for old ruby version. – Dominican