javacard crypto problem (RSA)

Hi,

I want to encrypt a 96 bytes long buffer X with a RSA key.

This key has a 1 byte public exponent, and a 96 bytes long secret modulus.

here's my code :

Key k = KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PRIVATE,

KeyBuilder.LENGTH_RSA_768,false);

((RSAPrivateKey) k).setExponent(expo, (short) 0, 1);

((RSAPrivateKey) k).setModulus(Sic, (short) 0, 96);

Cipher c = Cipher.getInstance(Cipher.ALG_RSA_NOPAD,false);

c.init(key, Cipher.MODE_ENCRYPT);

result =newbyte[96];

c.doFinal(X, (short) 0, (short) X.length, result, (short) 0);

What I get is an CryptoException.ILLEGAL_VALUE exception.

And if replace the Cipher.ALG_RSA_NOPAD

algorithm for the cipher by another one ( Cipher.ALG_RSA_PKCS1

, for example), I get a CryptoException.ILLEGAL_USE exception...

Can anyone tell me what's wrong with this code? (when I tested with a KeyPair generation, it worked, but I want to set my own values for the key expo and modulus. what if I did that after a generation by a KeyPair generation process?)

Thank you!

[1411 byte] By [jillemasha] at [2007-11-26 14:05:47]
# 1
Ok, sorry, I forgot to notify you that my problem has been solved : I used a wrong value for the key. So thanks to a Java SE program, I generated correct values for my RSA public and private keys.
jillemasha at 2007-7-8 1:50:46 > top of Java-index,Security,Cryptography...