Page 1 of 1

My code doesn't work with RSA key

Posted: Tue Mar 22, 2016 3:46 am
by conliaOdk
I am working on a java card project. But now I have difficulty to continue.
I can't do RSA key with a length different than 512 bit. As my codes show, I try to throw a CryptoException. but it doesn't show any error message. Could anybody tell me where I made the mistake in my code? Thanks very much

Here is my code:

Code: Select all

try{
keym = new KeyManager((short)1024);
}catch(Exception e){}

public RSAKey(short size) throws Exception{

     bufferA = new byte[size];
     bufferB = new byte[size];

paireDeClef = new KeyPair(KeyPair.ALG_RSA,KeyBuilder.LENGTH_RSA_1024);

paireDeClef.genKeyPair();
publicKey = (RSAPublicKey)paireDeClef.getPublic();
privateKey = (RSAPrivateKey)paireDeClef.getPrivate();

cip = Cipher.getInstance(Cipher.ALG_RSA_PKCS1,false);
}

Re: My code doesn't work with RSA key

Posted: Tue Mar 22, 2016 4:54 am
by Bodewes
Try to use KeyPair.ALG_RSA_CRT instead of KeyPair.ALG_RSA.

The private key may be an RSA CRT Private key.

Re: My code doesn't work with RSA key

Posted: Tue Mar 22, 2016 4:59 am
by btwtiger
Hey bro.

It seems that you are only catching the exception and not printing the exception out.