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!