Hello,
> 
> I am trying the below commands what is going wrong,
> 
>  
> 
> [EMAIL PROTECTED] crypt]$ openssl ecparam -outform DER -out ec-key.pem
> -name secp224r1 -genkey
> 
> [EMAIL PROTECTED] crypt]$ openssl ec -inform DER -in ec-key.der -text
> -noout
> 
> read EC key
> 
> unable to load Key
> 
> 19331:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong
> tag:tasn_dec.c:1294:
> 
> 19331:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested
> asn1 error:tasn_dec.c:380:Type=EC_PRIVATEKEY
> 
> 19331:error:10092010:elliptic curve routines:d2i_ECPrivateKey:EC
> lib:ec_asn1.c:1116:
I think that you get this error because EC parameters and EC key is
merged together in this DER file (which should not happen).
For example, generate EC key in PEM format:

$ openssl ecparam -outform PEM -out ec-key.pem -name secp224r1 -genkey
$ cat  ec-key.pem
-----BEGIN EC PARAMETERS-----
BgUrgQQAIQ==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MGgCAQEEHFVlOjUCJx4/M/ZSOX8joo9DzJG0CCLw+VWOsUigBwYFK4EEACGhPAM6
AARj/uwQstxPCEmpiZfMVtKgzDV+vMcxvSXaHwQctha86FkRMHDNBkF/2KX3HkWB
LS6W8T/JBntFIA==
-----END EC PRIVATE KEY-----

and we have TWO things: EC parameters and key.
This is ok for PEM because PEM routines looks for proper
"------ SOMETHING --------" to get requested object.

For example to print EC key:

$ openssl ec -in ec-key.pem -inform PEM -text -noout
read EC key
Private-Key: (224 bit)
priv:
    55:65:3a:35:02:27:1e:3f:33:f6:52:39:7f:23:a2:
    8f:43:cc:91:b4:08:22:f0:f9:55:8e:b1:48
pub: 
    04:63:fe:ec:10:b2:dc:4f:08:49:a9:89:97:cc:56:
    d2:a0:cc:35:7e:bc:c7:31:bd:25:da:1f:04:1c:b6:
    16:bc:e8:59:11:30:70:cd:06:41:7f:d8:a5:f7:1e:
    45:81:2d:2e:96:f1:3f:c9:06:7b:45:20
ASN1 OID: secp224r1

Lets convert this key to DER:

$ openssl ec -in ec-key.pem -inform PEM -out ec-key.der -outform der

and look at ASN.1 objects:

$ openssl asn1parse -in ec-key.der -inform DER
    0:d=0  hl=2 l= 104 cons: SEQUENCE          
    2:d=1  hl=2 l=   1 prim: INTEGER           :01
    5:d=1  hl=2 l=  28 prim: OCTET STRING      [HEX
DUMP]:55653A3502271E3F33F652397F23A28F43CC91B40822F0F9558EB148
   35:d=1  hl=2 l=   7 cons: cont [ 0 ]        
   37:d=2  hl=2 l=   5 prim: OBJECT            :secp224r1
   44:d=1  hl=2 l=  60 cons: cont [ 1 ]        
   46:d=2  hl=2 l=  58 prim: BIT STRING        

Now, generate DER encoded key:

$ openssl ecparam -outform DER -out ec-key2.der -name secp224r1 -genkey
$ openssl asn1parse -in ec-key2.der -inform DER
    0:d=0  hl=2 l=   5 prim: OBJECT            :secp224r1
    7:d=0  hl=2 l= 104 cons: SEQUENCE          
    9:d=1  hl=2 l=   1 prim: INTEGER           :01
   12:d=1  hl=2 l=  28 prim: OCTET STRING      [HEX
DUMP]:52E1A2B1784953A5C2221FA387BCCE71C46547A7F014C1E2C1ACEBF4
   42:d=1  hl=2 l=   7 cons: cont [ 0 ]        
   44:d=2  hl=2 l=   5 prim: OBJECT            :secp224r1
   51:d=1  hl=2 l=  60 cons: cont [ 1 ]        
   53:d=2  hl=2 l=  58 prim: BIT STRING        

as you see, there is additional object and in this der file only EC key
should exist.

When trying:

$ openssl ec -in ec-key2.der -inform DER -text -noout
read EC key
unable to load Key
30131:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong
tag:tasn_dec.c:1294:
30131:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1
error:tasn_dec.c:380:Type=EC_PRIVATEKEY
30131:error:10092010:elliptic curve routines:d2i_ECPrivateKey:EC
lib:ec_asn1.c:1116:

we get error, but after removing this object:

$ dd if=ec2-key.der of=ec-key3.der skip=7 bs=1
$ openssl asn1parse -in ec-key3.der -inform der
    0:d=0  hl=2 l= 104 cons: SEQUENCE          
    2:d=1  hl=2 l=   1 prim: INTEGER           :01
    5:d=1  hl=2 l=  28 prim: OCTET STRING      [HEX
DUMP]:52E1A2B1784953A5C2221FA387BCCE71C46547A7F014C1E2C1ACEBF4
   35:d=1  hl=2 l=   7 cons: cont [ 0 ]        
   37:d=2  hl=2 l=   5 prim: OBJECT            :secp224r1
   44:d=1  hl=2 l=  60 cons: cont [ 1 ]        
   46:d=2  hl=2 l=  58 prim: BIT STRING        
$ openssl ec -in ec-key3.der -inform DER -text -noout
read EC key
Private-Key: (224 bit)
priv:
    52:e1:a2:b1:78:49:53:a5:c2:22:1f:a3:87:bc:ce:
    71:c4:65:47:a7:f0:14:c1:e2:c1:ac:eb:f4
pub: 
    04:68:d8:51:38:cf:92:d2:b7:4a:a6:a1:68:ba:e3:
    77:ba:44:ba:e8:c0:99:0d:0e:4a:93:b4:29:6f:c8:
    90:d9:96:c0:21:9b:4b:fb:eb:22:53:1f:2c:b8:97:
    d7:1f:88:d6:9e:0d:c8:38:cf:96:3b:e4
ASN1 OID: secp224r1

we have correct EC key.

Best regards,
-- 
Marek Marcola <[EMAIL PROTECTED]>

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [email protected]
Automated List Manager                           [EMAIL PROTECTED]
  • EC C K KIRAN-KNTX36
    • Re: EC Florian MANACH
    • Re: EC Marek Marcola
    • EC C K KIRAN-KNTX36

Reply via email to