title: Java equivalent of .NET RSACryptoServiceProvider with SHA-1
body: <p>I have the following data signing code in C#</p>
  
  <pre><code>RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
  
  string PrivateKeyText = "&lt;RSAKeyValue&gt;&lt;Modulus&gt;....&lt;/D&gt;&lt;/RSAKeyValue&gt;";
  
  rsa.FromXmlString(PrivateKeyText);
  
  string data = "my data";        
  
  byte[] SignedByteData = rsa.SignData(Encoding.UTF8.GetBytes(data), new SHA1CryptoServiceProvider());
  </code></pre>
  
  <p>and I want reproduce the same code in Java (Android):</p>
  
  <pre><code>String modulusElem = "...";
  String expElem = "...";
  
  byte[] expBytes = Base64.decode(expElem, Base64.DEFAULT);
  byte[] modulusBytes = Base64.decode(modulusElem, Base64.DEFAULT);
  
  BigInteger modulus = new BigInteger(1, modulusBytes);
  BigInteger exponent = new BigInteger(1, expBytes);
  
  try {
      KeyFactory factory = KeyFactory.getInstance("RSA");
  
      Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1PADDING");
  
      String data = "my data";
  
      MessageDigest md = MessageDigest.getInstance("SHA-1");
      byte[] hashedData = md.digest(data.getBytes("UTF-8"));
  
      RSAPublicKeySpec pubSpec = new RSAPublicKeySpec(modulus, exponent);
  
      PublicKey publicKey = factory.generatePublic(pubSpec);
  
      cipher.init(Cipher.ENCRYPT_MODE, publicKey);
  
      byte[] SignedByteData = cipher.doFinal(hashedData);
  
  } catch (Exception e){
  
  }
  </code></pre>
  
  <p>But I get mismatched output byte arrays. Where am I wrong and What should be the transformation used in <code>Cipher.getInstance(...)</code> ?</p>