Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which padding is used by javax.crypto.Cipher for RSA

I need to decrypt messages via RSA in order to send it over an unsecured channel, but I'm afraid of the Padding Oracle Attack. Therefore I already have asked the follwoing questions:

  1. How to verify the integrity of RSA encrypted messages?
  2. How to ensure message integrity for RSA ciphers by using javax.crypto.Cipher

Like suggested in the first question,

However, since you are using a high level cryptographic library, this is something you shouldn't have to worry about. The writers of that library should have taken care of it.

I shouldn't consider about. As far I know, the RSA implementation of PKCS#1 v1.5 is vulnerable to the Padding Oracale Attack whereby OAEP isn't (assumed it's implemented correctly)

Hence I want to know which padding implementation is used by javax.crypt.Cipher by Java 7

like image 813
My-Name-Is Avatar asked Aug 16 '15 09:08

My-Name-Is


1 Answers

It depends on the chosen or default provider which padding is actually used when you instantiate a Cipher without fully qualifying it like:

Cipher.getInstance("RSA")

Doing so is a bad practice, because if you switch Java implementations, there might be different defaults and suddenly, you won't be compatible with the old ciphertexts anymore. Always fully qualify the cipher.

As I said before, the default will probably (there are many providers, one can't be sure) be PKCS#1 v1.5 padding. If you need another, you would have to specify it. If you want to use OAEP, here is a fully qualified cipher string from here:

Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
like image 170
Artjom B. Avatar answered Nov 15 '22 19:11

Artjom B.