生成 DER 格式的 ECDSA 密钥对
Generate ECDSA key pair in DER format
我想使用 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:
ecparam -genkey
默认输出 both 参数和密钥;在 PEM 中,reader 可以将这些和 select 关键部分分开,但在 DER 中不能。 添加-noout
来抑制参数。 (是的,你想要两者 -out file -noout
,尽管它看起来很矛盾。)
(我使用从上游源构建的 1.0.2l 和 1.1.0f 进行了复制。)
我想使用 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:
ecparam -genkey
默认输出 both 参数和密钥;在 PEM 中,reader 可以将这些和 select 关键部分分开,但在 DER 中不能。 添加-noout
来抑制参数。 (是的,你想要两者 -out file -noout
,尽管它看起来很矛盾。)
(我使用从上游源构建的 1.0.2l 和 1.1.0f 进行了复制。)