title: Read ECC private key PEM into AsymmetricCipherKeyPair c# bouncy castle
body: <p>I generate an ECC key pair in PEM format using Bouncy Castle using:</p>
  <pre><code>var curve = ECNamedCurveTable.GetByName(&quot;secp256k1&quot;);
  var domainParams = new ECDomainParameters(curve.Curve, curve.G, curve.N, curve.H, curve.GetSeed());
  
  var secureRandom = new SecureRandom();
  var keyParams = new ECKeyGenerationParameters(domainParams, secureRandom);
  
  var generator = new ECKeyPairGenerator(&quot;ECDSA&quot;);
  generator.Init(keyParams);
  AsymmetricCipherKeyPair keyPair = generator.GenerateKeyPair();
  TextWriter textWriter = new StringWriter();
  PemWriter pemWriter = new PemWriter(textWriter);
  pemWriter.WriteObject(keyPair.Private);
  pemWriter.Writer.Flush();
  string pem_privatekey = textWriter.ToString();
  </code></pre>
  <p>My current ECC private key is:</p>
  <pre><code>-----BEGIN EC PRIVATE KEY-----MIIBUQIBAQQgyDHBaj30dcIsS4otdOXR8ue+rZDwHcGEjxwle3H24W6ggeMwgeACAQEwLAYHKoZIzj0BAQIhAP////////////////////////////////////7///wvMEQEIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABwRBBHm+Zn753LusVaBilc6HCwcCm/zbLc4o2VnygVsW+BeYSDradyajxGVdpPv8DhEIqP0XtEimhVQZnEfQj/sQ1LgCIQD////////////////////+uq7c5q9IoDu/0l6M0DZBQQIBAaFEA0IABHxw0PK0uEvnF1lwhkLmHUlVtQVUrLp/1EcKzfAm6xOL/I6LtQ9nXPxDNhaxf/rPtk3DkZ5CaO0hLr1trCRrJz8=-----END EC PRIVATE KEY-----
  </code></pre>
  <p>I want to read this pem format private in a bouncy castle <code>ECPrivateKeyParameters</code> or <code>AsymmetricCipherKeyPair</code>  format.
  I am trying the following code.
  <code>pem</code> is the above private key string.</p>
  <pre><code>PemReader pr = new PemReader(new StringReader(pem));
  ECPrivateKeyParameters KeyPair = (ECPrivateKeyParameters)pr.ReadObject();
  </code></pre>
  <p>Why this returns null? Please correct me.</p>