title: Why RSA encryption can return different results with C# and Java?
body: <p><strong>I using:</strong></p>
  
  <ul>
  <li>c#: RSACryptoServiceProvider</li>
  <li>JAVA: KeyFactory.getInstance("RSA")+Cipher</li>
  </ul>
  
  <p>I sending public key (exponent + modulus) as byte array from java to c#. It's ok, there is the same bytes. But when i try to encrypt some data with one key in Java and c# - there is different results.</p>
  
  <p><strong>Java Key Generation:</strong></p>
  
  <pre><code>KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
  keyGen.initialize( Config.CRYPTO_KEY_NUM_BITS );
  
  m_KeyPair = keyGen.genKeyPair();
  
  m_PublicKey = KeyFactory.getInstance("RSA").generatePublic(
   newX509EncodedKeySpec(m_KeyPair.getPublic().getEncoded()));
  
  byte[] exponent = m_PublicKey.getPublicExponent().toByteArray();
  byte[] modulus  = m_PublicKey.getModulus().toByteArray(); // then sending...
  </code></pre>
  
  <p><strong>C# Key Recieve:</strong></p>
  
  <pre><code>// Recieved...
  m_ExternKey = new RSAParameters();
  m_ExternKey.Exponent    = exponent;
  m_ExternKey.Modulus     = modulus;
  
  m_RsaExtern = new RSACryptoServiceProvider();
  m_RsaExtern.ImportParameters(m_ExternKey);
  
  byte[] test = m_RsaExtern.Encrypt(bytesToEncrypt, true);
  </code></pre>
  
  <p>and problem is that encrypted bytes is different.</p>
  
  <p>Thank you.</p>