title: RSA/ECB/PKCS1Padding with DECRYPT_MODE
body: <p>I am trying to decrypt a string with public key to compare with a hash. The code is the followig</p>
  
  <pre><code>byte[] dectyptedText = null;
  Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
  cipher.init(Cipher.DECRYPT_MODE, key);
  dectyptedText = cipher.doFinal(text);
  return dectyptedText;
  </code></pre>
  
  <p>The above code generates a string like this (base64encode)</p>
  
  <p><strong>MCEwCQYFKw4DAhoFAAQUy3qkZYgfRVo2Sv1F9bHa3pDs044=</strong></p>
  
  <p>The hash is generated by the following code</p>
  
  <pre><code> byte[] key = stringToHash.getBytes();
   MessageDigest md = MessageDigest.getInstance("SHA-1");
   hash = md.digest(key);
  </code></pre>
  
  <p>The above code generates a sample hash like the following</p>
  
  <p><strong>y3qkZYgfRVo2Sv1F9bHa3pDs044</strong>=</p>
  
  <p>If you notice both has the correct hash which is <strong>y3qkZYgfRVo2Sv1F9bHa3pDs044</strong>= 
  But the decrypt code generates and prepends an extra <strong>MCEwCQYFKw4DAhoFAAQU</strong></p>
  
  <p>Dont understand how this extra thing is added and why.</p>
  
  <p>Can please somebody throw some light on this ?</p>
  
  <p>Thanks</p>
  
  <p>prem</p>