From: Brian Candler Date: 2008-10-18T01:04:59+09:00 Subject: Re: RSA public_encrypt bug? Dani Pardo wrote: > Actually, what I've found out is that after populating the modulus > and exponent, if I print the key: > > -- > rsa.n = OpenSSL::BN.new f.gets > rsa.e = OpenSSL::BN.new f.gets > > puts rsa.to_text > --- > > The modulus that #to_text reports doesn't ressemble what I have on > the public key I've got on a text file.. :? You want to post your n and e here? They are a *public* key, after all :-) > Also, the modulus reported by #to_text is 51 bytes (?), while the > public modulus I've got in the text file is 128 characters in hex, > which is 64 bytes. Aha! OpenSSL::BN reads decimal, not hex! Remember that irb is your friend: irb(main):001:0> require 'openssl' => true irb(main):002:0> x = OpenSSL::BN.new("1234") => 1234 irb(main):003:0> x = OpenSSL::BN.new("12AB") => 12 So try changing your code to: rsa.n = OpenSSL::BN.new(f.gets.to_i(16).to_s) Or more simply, you should just be able to write: rsa.n = f.gets.to_i(16) -- Posted via http://www.ruby-forum.com/.