Bug #4161
closedRSA encryption is not working on Android
0%
Description
When RSA encryption is used on Android, there will be an exception: "java.lang.ArrayIndexOutOfBoundsException: too much data for RSA block"
For example, the following code works well on MAC,
RsaKeyParams params = new RsaKeyParams(2048);
DecryptKey memberDecryptKey = RsaAlgorithm.generateKey(params);
Blob decryptKeyBlob = memberDecryptKey.getKeyBits();
EncryptKey memberEncryptKey = RsaAlgorithm.deriveEncryptKey(decryptKeyBlob);
Blob encryptKeyBlob = memberEncryptKey.getKeyBits();
EncryptParams encryptParams = new EncryptParams(EncryptAlgorithmType.RsaOaep);
Name name = new Name("test");
Data data = new Data(name);
Encryptor.encryptData(data, decryptKeyBlob, name,
encryptKeyBlob, encryptParams);
But when it is run on Android, there will be an exception:
java.lang.ArrayIndexOutOfBoundsException: too much data for RSA block
at com.android.org.bouncycastle.jcajce.provider.asymmetric.rsa.CipherSpi.engineDoFinal(CipherSpi.java:462)
at javax.crypto.Cipher.doFinal(Cipher.java:1340)
at net.named_data.jndn.encrypt.algo.RsaAlgorithm.encrypt(RsaAlgorithm.java:170)
at net.named_data.jndn.encrypt.algo.Encryptor.encryptAsymmetric(Encryptor.java:193)
at net.named_data.jndn.encrypt.algo.Encryptor.encryptData(Encryptor.java:91)
it's because the implementation of Cipher.java on Android is different from that of oracle java
Updated by Anonymous over 7 years ago
- Status changed from New to Closed
- Assignee set to Anonymous
Thanks for the bug report. I was able to reproduce it on Android. I added code to handle this case on Android. The fix is merged to master:
https://github.com/named-data/jndn/commit/38f06c01414da2192fb5ff7e4db823d8407fe9af