title: Get public key from private key in Bouncy Castle C#
body: <p>So I have an encrypted private key PEM.  I can read it and get the private key with the following:</p>
  
  <pre><code>AsymmetricKeyParameter key;
  using (var sr = new StringReader(pem))
  using (var pf = new PassowrdFinder { Password = password })
  {
    var reader = new PemReader(sr, pf);
    key = (AsymmetricKeyParameter)reader.ReadObject();
  }
  </code></pre>
  
  <p>I also need the public key, to create the SPKI later on.  I tried</p>
  
  <pre><code>var keyPair = new AsymmetricCipherKeyPair(key, key);
  </code></pre>
  
  <p>Which fails with <code>System.ArgumentException: Expected a public key Parameter name: publicParameter</code>.</p>
  
  <p>My question is: How to get the public key from a private key?</p>