KeyPair and Cipher.init() Help

Hi,

I've generated a keypair using KeyPairGenerator and after that saving the public and private keys individually to files as hex. Now when I read the hex back and used SecretKeySpec(byte[],"RSA") to reinstate it as a Key object and plug that into Cipher.init(Cipher.ENCRYPT_MODE,pubKey,random) I come up with an exception.

I've come to discover that if I feed a Key that was generated within the class, that method call is fine, but if I read a pre-generated key from a file, that method doesn't like it. Any ideas?

Regards,

Dave

[566 byte] By [yipsheea] at [2007-11-27 6:13:31]
# 1
Just to clarify, I use key.getEncoded() to retrieve the key as a byte array and convert that to a hex string. I then save the hex string to a text file.
yipsheea at 2007-7-12 17:22:02 > top of Java-index,Security,Cryptography...
# 2

> Just to clarify, I use key.getEncoded() to retrieve

> the key as a byte array and convert that to a hex

> string. I then save the hex string to a text file.

Can you post your code because its really difficult to find out what the problem is without looking at the code. Also please specify what exception is being generated and where.

Thanks.

DarumAa at 2007-7-12 17:22:02 > top of Java-index,Security,Cryptography...