Project

General

Profile

Actions

Bug #4161

closed

RSA encryption is not working on Android

Added by Haitao Zhang almost 7 years ago. Updated almost 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Start date:
07/05/2017
Due date:
% Done:

0%

Estimated time:

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

Actions #1

Updated by Anonymous almost 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

Actions

Also available in: Atom PDF