Project

General

Profile

Actions

Bug #4161

closed

RSA encryption is not working on Android

Added by Haitao Zhang over 7 years ago. Updated over 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

Also available in: Atom PDF