Search code examples
rubyopensslrsalong-integerbignum

Ruby error "bignum too big to convert into long"


I'm trying to generate an RSA keypair in ruby with:

OpenSSL::PKey::RSA.generate(aReallyLongBignum, 65537)

but I am getting the following error:

bignum too big to convert into long

However it works in python using RSA.construct. Is there any way for this to work in ruby? I've looked everywhere. Really lost here. I am not trying to only take a section of this number at a time, I need to be able to pass the whole number to RSA.generate


Solution

  • I was able to solve this using OpenSSL::BN and setting it after creating an instance of OpenSSL::Pkey::RSA

    key   = OpenSSL::PKey::RSA.new
    key.e = OpenSSL::BN.new(65537)
    key.n = OpenSSL::BN.new(aReallyLongBignum)