生成 DER 格式的 ECDSA 密钥对

Dur*_*ndA 0 openssl ecdsa

我想使用 OpenSSL CLI生成DER 格式的secp256r1密钥对。

我正在使用以下命令:

$ openssl ecparam -name prime256v1 -outform der -genkey -out privkey.der
$ openssl ec -inform der -in privkey.der -pubout -outform der -out pubkey.der
Run Code Online (Sandbox Code Playgroud)

但是,第二个命令触发了无法加载密钥错误:

read EC key
unable to load Key
139911012984576:error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag:crypto/asn1/tasn_dec.c:1112:
139911012984576:error:0D07803A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:crypto/asn1/tasn_dec.c:274:Type=EC_PRIVATEKEY
139911012984576:error:10092010:elliptic curve routines:d2i_ECPrivateKey:EC lib:crypto/ec/ec_asn1.c:925:
Run Code Online (Sandbox Code Playgroud)

dav*_*085 5

ecparam -genkey默认情况下输出二者的PARAMS和密钥; 在 PEM 中,读者可以将它们分开并选择关键部分,但在 DER 中则不能。添加-noout以抑制参数。(是的,-out file -noout即使看起来矛盾,您也想要两者。)

(我使用从上游源构建的 1.0.2l 和 1.1.0f 进行了复制。)