views:

129

answers:

1

I need encrypt data using exactly the PKCS#1 V2.0 encryption method (defined in item 7.2.1 of the PKCS#1V2 specification).

Is it already implemented for Java?

I'm thinking in something like just pass a parameter to javax.crypto.Cipher specifying "PKCS#1V2", I wonder if there is something like this?

+1  A: 

PKCS#1 v2.0 encryption is usually called OAEP encryption. So:

Cipher.getInstance("RSA/ECB/OAEPWithSHA1AndMGF1Padding");

The place to look is the Java Cryptography Architecture documents: Standard Algorithm Name Documentation or Sun Providers Documentation.

As you can see the SunJCE provider supports the following variations of OAEP:

  • OAEPWITHMD5ANDMGF1PADDING
  • OAEPWITHSHA1ANDMGF1PADDING
  • (OAEPWITHSHA-1ANDMGF1PADDING)
  • OAEPWITHSHA-256ANDMGF1PADDING
  • OAEPWITHSHA-384ANDMGF1PADDING
  • OAEPWITHSHA-512ANDMGF1PADDING
Rasmus Faber
Sun Providers Documentation, yes, Standard Algorithm Name Docs, no. Sun does not promise to implement everything they have reserved a name for. As an example, the "ECIES" algorithm name is reserved, but no Sun provider implements it.
GregS
The Standard Algorithm Name Documentation helps you find the correct name instead of "PKCS#1V2". The Sun Providers Documentation helps you find out whether the Sun provider implements it or if you should try to find another provider.
Rasmus Faber
@RasmusFaber Looks like OAEP (Optimal Asymmetric Encryption Padding) it's just the padding definition. Is PKCS1V2 just about padding?
Tom Brito
GregS
@Tom Brito: Basically yes.
Rasmus Faber
I didn't found this names, but found XMLCipher.RSA_OAEP in apache commons, that is the same thing. Anyway, thanks!
Tom Brito