I found the hard way that in Oracle's Java standard crypto provider
Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
uses MFG1 instanciated with SHA-1; SHA-256 is only used to hash the label (in practice empty). The only solution that I found to actually use SHA-256 in MFG1 (helped by that answer and comment) was using an alternate form of Cipher.init
:
cipher.init(Cipher.DECRYPT_MODE, privKey, new OAEPParameterSpec(
"SHA-256", "MGF1", MGF1ParameterSpec.SHA256, PSource.PSpecified.DEFAULT
));
Question: is there a transformation that Cipher.getInstance
will recognize, with effect similar to "RSA/ECB/OAEPWithSHA-256AndMGF1Padding"
, except with MGF1 using SHA-256?
ECB is a block cipher mode of operation. RSA is a public key encryption scheme, not a block cipher. Generally, it doesn't make sense to encrypt long messages directly with RSA.
When implemented with certain trapdoor permutations (e.g., RSA), OAEP is also proven to be secure against chosen ciphertext attack. OAEP can be used to build an all-or-nothing transform.
Data encryption/decryption is one of the main security method commonly used in payment gateways. It gets encrypted by using the payment gateway's public key and can only be decrypted by the payment gateway's private key.
Another hash function should map arbitrary sized input to arbitrary sized output. Such hash function is called "mask generation function" (MGF). The related RFC defines only one such function, MGF1: One mask generation function is given here: MGF1, which is based on a hash function.
No, there isn't.
Java is open source. If unsure you can take a look at the sources for the OpenJDK.
In the init
method of com.sun.crypto.provider.RSACipher
it reads:
spec = new OAEPParameterSpec(oaepHashAlgorithm, "MGF1",
MGF1ParameterSpec.SHA1, PSource.PSpecified.DEFAULT);
I've checked this up to Java 8 update 60 for the OpenJDK. As you can see, you need to use the algorithm parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With