Problem: Decryption by PKCS#1 RSA engine returns always 245 bytes even when smaller amount of data was inserted for encryption. Data itself are correctly decrypted.
Version used: jcardsim-2.2.2-all.jar
Code fragment to replicate issue:
public void testJCardSimRSADecryptBug() throws Exception {
KeyPair keyPair = new KeyPair(KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_2048);
keyPair.genKeyPair();
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
RSAPrivateCrtKey privateKey = (RSAPrivateCrtKey) keyPair.getPrivate();
Cipher rsaEngine = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false);
rsaEngine.init(publicKey, Cipher.MODE_ENCRYPT);
byte[] buffer = new byte[256];
short dataLen = 16;
Util.arrayFillNonAtomic(buffer, (short) 0, dataLen, (byte) 1);
short encLen = rsaEngine.doFinal(buffer, (short) 0, dataLen, buffer, (short) 0);
assert(encLen == 256);
// For RSA2048, data len is 16, but when decrypted back, we will get 245 bytes
rsaEngine.init(privateKey, Cipher.MODE_DECRYPT);
short decLen = rsaEngine.doFinal(buffer, (short) 0, encLen, buffer, (short) 0);
assert(decLen == dataLen);
}
Problem: Decryption by PKCS#1 RSA engine returns always 245 bytes even when smaller amount of data was inserted for encryption. Data itself are correctly decrypted.
Version used: jcardsim-2.2.2-all.jar
Code fragment to replicate issue: