以DER格式生成ECDSA密钥对

时间:2018-05-08 13:42:22

标签: 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

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

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:

1 个答案:

答案 0 :(得分:4)

ecparam -genkey默认输出两者参数和密钥;在PEM中,读者可以将这些分开并选择关键部分,但不能选择DER。 添加-noout 以取消参数。 (是的,你想要两个-out file -noout,即使它看起来很矛盾。)

(我用1.0.2l和1.1.0f复制,两者都是从上游源构建的。)

相关问题