title: How to sign and validate RSA PKCS#1 v2.0 signatures in Java
body: <p>I'm trying to sign and validate signature in RSA+SHA1 with PKCS1 v2.0 padding.
  I haven't found in the documentation (JDK or JCE) which algorithm/padding I have to use. 
  It seems that I've to use OAEP padding but I didn't succeed:</p>
  
  <p>For validation, I've tried via Cipher in DECRYPT_MODE with the public key sent by the signer:</p>
  
  <pre><code>Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWITHSHA1ANDMGF1PADDING", "SunJCE"); 
  cipher.init(Cipher.DECRYPT_MODE, pub); //exception !
  </code></pre>
  
  <p>But I got an exception:</p>
  
  <pre><code>  java.security.InvalidKeyException: OAEP cannot be used to sign or verify signatures
          at com.sun.crypto.provider.RSACipher.init(RSACipher.java:303)
          at com.sun.crypto.provider.RSACipher.engineInit(RSACipher.java:207)
      ...
  </code></pre>
  
  <p>(For unknown reason, OAEPWITHSHA1ANDMGF1PADDING is only accepted with ENCRYPT_MODE+PUBLIC KEY or DECRYPT_MODE+PRIVATE KEY, the opposite that I want to do....)</p>
  
  <p>For signature, I'm trying to use Signature but I don't know which algorithm to use:</p>
  
  <pre><code>Signature mySig2 = Signature.getInstance("SHA1withRSAandMGF1");
  </code></pre>
  
  <p>Doesn't work :</p>
  
  <pre><code>java.security.NoSuchAlgorithmException: SHA1withRSAandMGF1 Signature not available
      at java.security.Signature.getInstance(Signature.java:229)
  ...
  </code></pre>
  
  <p>Can somebody help me?</p>