Skip to content

Support reading SEC1 ECC keys with parameters in PemReader #663

@ceztko

Description

@ceztko

Is your feature request related to a problem or specific use case? Please describe.

The following command:

openssl ecparam -name prime256v1 -genkey -out ec_key.pem

Produces a ECC key in SEC1 format like the following:

-----BEGIN EC PARAMETERS-----
BggqhkjOPQMBBw==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEILvssMloOUDHj0tI5SwZHmCcOwi1AZirx8J4cV5uFH+aoAoGCCqGSM49
AwEHoUQDQgAEh9bOpvg/DH2sdLgFiH5tMneEdm8jPFWRlk2HHvaLTZ07m9AMONfp
kAOlGe1MxyyS72fq9/JVmaP8grnDTpQuww==
-----END EC PRIVATE KEY-----

This key can't be parsed by PemReader with the following code:

using (var strReader = new StreamReader(stream))
{
    var pemReader = new PemReader(strReader);
    while (strReader.Peek() != -1)
    {
       var obj = pemReader.ReadObject();
    }
}

...as it will crash with System.IO.IOException: unrecognised object: EC PARAMETERS. It seems the Java code for reading those was not ported to bcsharp.

Describe the solution you'd like

PemReader should be able to parse such key.

Describe alternatives you've considered

One can produce a PKCS8 key instead with

openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out ec_key.pem

Or produce a SEC1 key without specifying the parameters:

openssl ecparam -name prime256v1 -genkey -noout -out ec_key.pem

Product deployment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions