title: Encode a RSA public key to DER format
body: <p>I need a RSA public key encoded into DER format.</p>
  
  <p>The key-pair is generated using RSACryptoServiceProvider.</p>
  
  <p>What I'm looking for is the c# equivalent to the java:</p>
  
  <pre><code>PublicKey pubKey = myPair.getPublic();
  byte[] keyBytes = pubKey.getEncoded();
  </code></pre>
  
  <p>I have tried looking into BouncyCastle but got lost so if the solution is there any pointers are welcome.</p>