title: Reading elliptic curve private key from file with BouncyCastle
body: <p>The BouncyCastle cryptography APIs allow for creating and verifying digital signatures using the regular <code>java.security</code> package objects, such as <code>java.security.PublicKey</code>, <code>java.security.PrivateKey</code> and their container <code>java.security.KeyPair</code>.</p>
  
  <p>Suppose I use OpenSSL to create a .pem (or, if easier, a .der file) containing the elliptic curve private key I want to use in my application. For example, it looks like this:</p>
  
  <pre><code>-----BEGIN EC PARAMETERS-----
  BgUrgQQACg==
  -----END EC PARAMETERS-----
  -----BEGIN EC PRIVATE KEY-----
  MHQCAQEEIDzESrZFmTaOozu2NyiS8LMZGqkHfpSOoI/qA9Lw+d4NoAcGBSuBBAAK
  oUQDQgAE7kIqoSQzC/UUXdFdQ9Xvu1Lri7pFfd7xDbQWhSqHaDtj+XY36Z1Cznun
  GDxlA0AavdVDuoGXxNQPIed3FxPE3Q==
  -----END EC PRIVATE KEY-----
  </code></pre>
  
  <p>How do I use the BouncyCastle APIs to obtain a <code>java.security.KeyPair</code> containing both this private key and a corresponding public key?</p>
  
  <p>Please note I want to use the APIs available in BouncyCastle 1.50 (which is current at the time of writing) and no deprecated APIs. This unfortunately excludes the <code>PEMReader</code> class used in other SO answers. Furthermore, this question is specific to the format of elliptic curves; they contain additional parameters when compared RSA or DSA key files.</p>