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!

