title: Pycrypto RSA PKCS1 OAEP SHA256 Interoperability with Java
body: <p>I'm using the following code in Python + Pycryptodome (Pycrypto fork) to encrypt a message using RSA PKCS#1 OAEP SHA256 (<code>RSA/ECB/OAEPWithSHA-256AndMGF1Padding</code>): </p>
  
  <pre><code>from Crypto.Cipher import PKCS1_OAEP
  from Cryptodome.Hash import SHA256
  cipher = PKCS1_OAEP.new(key=self.key, hashAlgo=SHA256))
  ciphertext = cipher.encrypt(cek)
  </code></pre>
  
  <p>and the following code in Java to decrypt it:</p>
  
  <pre><code>Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
  cipher.init(Cipher.DECRYPT_MODE, privateKey);
  
  byte[] cek = cipher.doFinal(ciphertext);
  </code></pre>
  
  <p>However, I'm getting:</p>
  
  <pre><code>Exception in thread "main" javax.crypto.BadPaddingException: Decryption error
      at sun.security.rsa.RSAPadding.unpadOAEP(RSAPadding.java:499)
      at sun.security.rsa.RSAPadding.unpad(RSAPadding.java:293)
      at com.sun.crypto.provider.RSACipher.doFinal(RSACipher.java:363)
      at com.sun.crypto.provider.RSACipher.engineDoFinal(RSACipher.java:389)
      at javax.crypto.Cipher.doFinal(Cipher.java:2165)
  </code></pre>