From: Aaron Patterson Date: 2007-08-08T08:25:07+09:00 Subject: Re: Help with OpenSSL RSA On Wed, Aug 08, 2007 at 07:05:22AM +0900, Starfry Starfry wrote: > Hi, > I'm writing a little code to do some RSA stuff and I need to extract the > public exponent and modulus for passing to a browser that will use them > in Javascript. > > I've done considerable digging but have drawn a blank as I can't find > any complete documentation of the full RSA class definition. > > What I am trying right now is to do: > > key = RSA.new(1024) > private_key = key.to_pem > public_modulus = key.public_key.n > public_exponent = key.public_key.e > > This generates a new key and assigns the private key to a variable. I'd > like to get the public exponent and modulus returned as a hex encoded > string, similar to the output of "openssl rsa -noout -modulus" > > However, I can't find suitable documentation so I don't know what method > (if any) I can use. I'd hoped for "key.public_key.n.to_h" but that does > not seem to work. How about Base64 ecoding? [key.public_key.n.to_s].pack('m') -- Aaron Patterson http://tenderlovemaking.com/