RandomData Encryption Using RSA 2048
Posted: Tue Jun 21, 2016 6:08 am
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);
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);