0

When I use the RSA/ECB/OAEPPadding algorithm in the encryption method below, an error gets thrown in Android:

Error:javax.crypto.IllegalBlockSizeException: error:04000072:RSA routines:OPENSSL_internal:DATA_TOO_LARGE_FOR_KEY_SIZE
      javax.crypto.IllegalBlockSizeException: error:04000072:RSA routines:OPENSSL_internal:DATA_TOO_LARGE_FOR_KEY_SIZE.

Before this, I was using the RSA/ECB/PKCS1Padding algorithm. After the switch to the RSA/ECB/OAEPPadding algorithm, I am getting the above exception, however, the codebase did not change.

I tried using this code:

Key key = ...;
Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPPadding");
// To use SHA-256 the main digest and SHA-1 as the MGF1 digest
cipher.init(Cipher.ENCRYPT_MODE, key, new OAEPParameterSpec("SHA-256", "MGF1", MGF1ParameterSpec.SHA1, PSource.PSpecified.DEFAULT));
// To use SHA-256 for both digests
cipher.init(Cipher.ENCRYPT_MODE, key, new OAEPParameterSpec("SHA-256", "MGF1", MGF1ParameterSpec.SHA256, PSource.PSpecified.DEFAULT));

but I get this error:

CryptoHelper: Error:javax.crypto.BadPaddingException: error:0400007e:RSA routines:OPENSSL_internal:KEY_SIZE_TOO_SMALL
    javax.crypto.BadPaddingException: error:0400007e:RSA routines:OPENSSL_internal:KEY_SIZE_TOO_SMALL

Any help is appreciated!

0

1 Answer 1

-1
Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPPadding");
// To use SHA-256 the main digest and SHA-1 as the MGF1 digest
cipher.init(Cipher.ENCRYPT_MODE, key, new OAEPParameterSpec("SHA-256", "MGF1", MGF1ParameterSpec.SHA1, PSource.PSpecified.DEFAULT));
// To use SHA-256 for both digests

This code is working fine

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.