title: OpenSSL Elliptic Curve reading private key in DER form
body: <p>I have an EC private key in DER form that I want to transform to PEM form. But I cant read the DER form.</p>
  <p>The private key is generated as:</p>
  <pre><code>openssl ecparam -param_enc named_curve -check -name &quot;-secp384r1&quot; -genkey -noout -out &quot;params.pem&quot; -outform pem
  openssl pkcs8 -in &quot;params.pem&quot; -inform pem -topk8 -nocrypt -out &quot;private.der&quot; -outform der
  </code></pre>
  <p>If I then try to read the private key with</p>
  <pre><code>openssl ec -in private.der -inform der 
  </code></pre>
  <p>I get the error:</p>
  <pre><code>read EC key
  unable to load Key
  4674530924:error:0DFFF0A8:asn1 encoding routines:CRYPTO_internal:wrong tag:/AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-47.140.1/libressl-2.8/crypto/asn1/tasn_dec.c:1144:
  4674530924:error:0DFFF03A:asn1 encoding routines:CRYPTO_internal:nested asn1 error:/AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-47.140.1/libressl-2.8/crypto/asn1/tasn_dec.c:717:
  4674530924:error:0DFFF03A:asn1 encoding routines:CRYPTO_internal:nested asn1 error:/AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-47.140.1/libressl-2.8/crypto/asn1/tasn_dec.c:646:Field=privateKey, Type=EC_PRIVATEKEY
  4674530924:error:10FFF010:elliptic curve routines:CRYPTO_internal:EC lib:/AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-47.140.1/libressl-2.8/crypto/ec/ec_asn1.c:1353:
  </code></pre>
  <p>If I try with:</p>
  <pre><code>openssl pkcs8 -in private.der -inform der
  </code></pre>
  <p>Then I get these error:</p>
  <pre><code>Error reading key
  4460752492:error:0DFFF0A8:asn1 encoding routines:CRYPTO_internal:wrong tag:/AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-47.140.1/libressl-2.8/crypto/asn1/tasn_dec.c:1144:
  4460752492:error:0DFFF03A:asn1 encoding routines:CRYPTO_internal:nested asn1 error:/AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-47.140.1/libressl-2.8/crypto/asn1/tasn_dec.c:317:Type=X509_ALGOR
  4460752492:error:0DFFF03A:asn1 encoding routines:CRYPTO_internal:nested asn1 error:/AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-47.140.1/libressl-2.8/crypto/asn1/tasn_dec.c:646:Field=algor, Type=X509_SIG
  </code></pre>
  <p>Note that if I generate in PEM format directly:</p>
  <pre><code>openssl pkcs8 -in &quot;params.pem&quot; -inform pem -topk8 -nocrypt -out &quot;private.pem&quot; -outform pem
  </code></pre>
  <p>Then I have no problem reading it with:</p>
  <pre><code>openssl ec -in private.pem -inform pem
  </code></pre>