title: why .net RSACryptoServiceProvider.FromXmlString throw bad data error
body: <p>I have a RSA private key which generated by Java in server side, my client side is a .net application, So I need to covert the private key into .net accepted format.</p>
  
  <p>Here is my code in server side written by java:           </p>
  
  <pre class="lang-java prettyprint-override"><code> public String getRSAPrivateKeyAsNetFormat(byte[] encodedPrivkey) {
          try {
              StringBuffer buff = new StringBuffer(2048);    
              PKCS8EncodedKeySpec pvkKeySpec = new PKCS8EncodedKeySpec(encodedPrivkey);
              KeyFactory keyFactory = KeyFactory.getInstance("RSA");                              
              RSAPrivateCrtKey pvkKey = (RSAPrivateCrtKey) keyFactory.generatePrivate(pvkKeySpec);
              buff.append("&lt;RSAKeyValue&gt;");   
              buff.append("&lt;Modulus&gt;" + b64encode(removeMSZero(pvkKey.getModulus().toByteArray())) + "&lt;/Modulus&gt;");       
              buff.append("&lt;Exponent&gt;" + b64encode(removeMSZero(pvkKey.getPublicExponent().toByteArray())) + "&lt;/Exponent&gt;");      
              buff.append("&lt;P&gt;" + b64encode(removeMSZero(pvkKey.getPrimeP().toByteArray())) + "&lt;/P&gt;");   
              buff.append("&lt;Q&gt;" + b64encode(removeMSZero(pvkKey.getPrimeQ().toByteArray())) + "&lt;/Q&gt;");    
              buff.append("&lt;DP&gt;" + b64encode(removeMSZero(pvkKey.getPrimeExponentP().toByteArray())) + "&lt;/DP&gt;");
              buff.append("&lt;DQ&gt;" + b64encode(removeMSZero(pvkKey.getPrimeExponentQ().toByteArray())) + "&lt;/DQ&gt;");
  buff.append("&lt;InverseQ&gt;" + b64encode(removeMSZero(pvkKey.getCrtCoefficient().toByteArray())) + "&lt;/InverseQ&gt;");    
              buff.append("&lt;D&gt;"+ b64encode(removeMSZero(pvkKey.getPrivateExponent().toByteArray())) + "&lt;/D&gt;");
              buff.append("&lt;/RSAKeyValue&gt;");    
              return buff.toString().replaceAll("[ \t\n\r]", "");
          } catch (Exception e) {
              System.out.println("324234234");
              System.err.println(e);
              return null;
          }
      }
  </code></pre>
  
  <p>the code to use private key in client side is like this, which written by .net    </p>
  
  <pre class="lang-cs prettyprint-override"><code>    using (var rsaProvider = new RSACryptoServiceProvider())
      {
         rsaProvider.FromXmlString(key);
      }
  </code></pre>
  
  <p>this code works for most of users, but FromXmlString method throw a "bad data" exception for one user. I don't know why it happends, Any information will be appreciated. Thank you very much.</p>