Page 1 of 1

RandomData Encryption Using RSA 2048

Posted: Tue Jun 21, 2016 6:08 am
by morva14
hi
i encrypt randomdata by using cipher ALG_RSA_NOPAD but some times its result is correct or not.
its Exeption throw is 0005.
i am comfeuzed i dont no what shoud i do

asymCipher = Cipher.getInstance(Cipher.ALG_RSA_NOPAD, false);
rsaPubKey = (RSAPublicKey) KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PUBLIC,

KeyBuilder.LENGTH_RSA_2048,false);
random = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);

randomData = JCSystem.makeTransientByteArray((short)10,JCSystem.CLEAR_ON_RESET);
byte[] temp = new byte[256];
byte[] outBuff= new byte[256];

random.generateData(randomData, (short)0,(short)randomData.length);
Util.arrayCopy(randomData,(short)0,temp,(short)0,(short)randomData.length);
short bLength = (short)(temp.length - randomData.length);
Util.arrayFillNonAtomic(temp,(short)randomData.length,bLength,(byte)0x00);

asymCipher.init(rsaPubKey, Cipher.MODE_ENCRYPT);
asymCipher.doFinal(temp,(short)0,(short)temp.length, outBuff, (short)0);

Re: RandomData Encryption Using RSA 2048

Posted: Tue Jun 21, 2016 8:54 am
by mabel
Pls show us public key and the temp data when you caught exception.

Could you also tell us whether the following code will be executed everytime you run your code?

Code: Select all

randomData = JCSystem.makeTransientByteArray((short)10,JCSystem.CLEAR_ON_RESET);
byte[] temp = new byte[256];
byte[] outBuff= new byte[256];

Re: RandomData Encryption Using RSA 2048

Posted: Tue Jun 21, 2016 10:24 am
by morva14
randomData = JCSystem.makeTransientByteArray((short)10,JCSystem.CLEAR_ON_RESET);
byte[] temp = new byte[256];
byte[] outBuff= new byte[256];

they are in to constractor class.

the result of random data encryption some time is correct and its sw is 9000 and some time it is throw cipherexception 0005

Re: RandomData Encryption Using RSA 2048

Posted: Wed Jun 22, 2016 1:59 am
by mabel
Could you tell me the card type you are using?

Re: RandomData Encryption Using RSA 2048

Posted: Wed Jun 22, 2016 2:18 pm
by morva14
I dont know what is type of my card. How can i underestand?

Re: RandomData Encryption Using RSA 2048

Posted: Wed Jun 22, 2016 10:23 pm
by mabel
I mean the card model, for instance, J3D081, A22CR, A40CR ..