Dani Pardo
10/17/2008 3:40:00 PM
On Fri, Oct 17, 2008 at 5:20 PM, Brian Candler <b.candler@pobox.com> wrote:
> Dani Pardo wrote:
>> Hi, I'm trying to encrypt some data with an RSA public key, this is
>> the code which is failing:
>
> Your life might be easier if you read your public key from a PEM file
> :-)
Yeah, but as you can figure out I don't have it. I have a file with
two lines, the module and the exponent.
> I don't know why your code doesn't work. However I have attached some
> code I wrote about 4 years ago which I used to construct a key from its
> parameters (before writing it out as a PEM). It seems you're doing the
> right things, but maybe the comments are relevant.
>
> I think I was using integers, so perhaps f.gets.to_i ?
> Also, you could try writing out a PEM, and then using that at the
> openssl command line, to check that your key is actually valid.
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.. :?
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.
My cryptographic skills are not very good, but any hint appreciated :)
--
Dani