title: Generating an RSA KeyPair and extracting modulus and exponent from Public Key in Android
body: <p>I generated a Public Private Key Pair in Android. Now I need to send my Public Key back to the Server for communicating with RSA Encryption. However, I am communicating with a .NET Server (in C#). Therefore I need to send my Public Key in the following format:</p>
  
  <pre><code>&lt;RSAKeyValue&gt;&lt;Modulus&gt;Modulus In Base 64&lt;/Modulus&gt;&lt;Exponent&gt;Exponent in Base 64&lt;/Exponent&gt;&lt;/RSAKeyValue&gt;
  </code></pre>
  
  <p>I generate the key Pair with the following code:</p>
  
  <pre><code>public static void generateKey() {
  
      try 
      {
          final KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
          keyGen.initialize(1024);
          final KeyPair key = keyGen.generateKeyPair();
          privateKey = key.getPrivate();
          publicKey = key.getPublic();
  
      } catch (NoSuchAlgorithmException e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>How can I extract the modulus and exponent of the PublicKey I just generated?</p>