6

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?

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
The Student
  • 27,520
  • 68
  • 161
  • 264

1 Answers1

8

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
  • 48,631
  • 24
  • 141
  • 189
  • 1
    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. – President James K. Polk Jun 01 '10 at 22:23
  • 2
    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 Jun 02 '10 at 05:12
  • @RasmusFaber Looks like OAEP (Optimal Asymmetric Encryption Padding) it's just the padding definition. Is PKCS1V2 just about padding? – The Student Jun 02 '10 at 14:15
  • @Tom Brito: Why don't read the spec for yourself? http://www.rfc-editor.org/cgi-bin/rfcdoctype.pl?loc=RFC&letsgo=3447&type=http&file_format=txt – President James K. Polk Jun 02 '10 at 15:27
  • I didn't found this names, but found XMLCipher.RSA_OAEP in apache commons, that is the same thing. Anyway, thanks! – The Student Jun 11 '10 at 17:40