Get key parameters from imported Elliptic Curve key in ASN.1 format

Dropper

I need to write code that gets as input Elliptic Curve key in ASN.1 format.

The input byte array is next:

308187020100301306072A8648CE3D020106082A8648CE3D030107046D306B0201010420E699203AC5BCFE36402EBD0AC9E8E21CC6FAD5828A61297EA747468FFF4DBB20A144034200047E05188A03EA81E853B9F6AC5F20DCA1A1CA828FD7CD5D92161FB2120C35EAC52EAB079ED01A510123057C322DDFF95E239D6063055BC90858D161D71DE707F8

Online parser shows me the next structure:

Result of online ASN.1 parser

To use key as I want I need to get public value X, public value Y and private value from this structure, at least I think so. But I do not know how.

I have searched information about OBJECT IDENTIFIER 1.2.840.10045.2.1 and OBJECT IDENTIFIER 1.2.840.10045.3.1.7. I've found this document. But there is no description of fields of ASN.1 structure.

How can I get required parameters from imported data?

Maarten Bodewes

It's commonly known as a PKCS#8 structure, which is the "Private-Key Information Syntax Specification". It only contains the unencrypted part of a PKCS#8 private key.

So this is in PKCS#8:

PrivateKeyInfo ::= SEQUENCE {
    version Version,
    privateKeyAlgorithm AlgorithmIdentifier {{PrivateKeyAlgorithms}},
    privateKey PrivateKey,
    attributes [0] Attributes OPTIONAL
}

The AlgorithmIdentifier is taken from PKCS#5

AlgorithmIdentifier { ALGORITHM-IDENTIFIER:InfoObjectSet } ::= SEQUENCE {
    algorithm ALGORITHM-IDENTIFIER.&id({InfoObjectSet}),
    parameters ALGORITHM-IDENTIFIER.&Type({InfoObjectSet}
    {@algorithm}) OPTIONAL
}

The Elliptic Curve Private Key structure:

ECPrivateKey ::= SEQUENCE {
    version        INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),
    privateKey     OCTET STRING,
    parameters [0] ECParameters {{ NamedCurve }} OPTIONAL,
    publicKey  [1] BIT STRING OPTIONAL
}

Oh, and encoded in DER, the Distinguished Encoding Rules (study version) - you may not be able to rule out BER completely, which is a more loosely defined and therefore harder to parse structure). PKCS#8 defines BER unfortunately.

Oh, yeah, the public key is in uncompressed point format. Don't forget to strip away the 00 from the bit string.

Happy parsing.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Reading elliptic curve private key from file with BouncyCastle

From Dev

Should elliptic curve for public key generation and signature computation be the same?

From Dev

OpenSSL Elliptic Curve reading private key in DER form

From Dev

Should elliptic curve for public key generation and signature computation be the same?

From Dev

Generate elliptic curve key pairs (EC_KEY_generate_key) in multiple threads using OpenSSL C library

From Dev

Using elliptic curve Diffie-Hellman with cofactor key for generating symmetric key

From Dev

Generate 1024 bit RSA keypair and save public key in ASN.1 format (hex) in node.js

From Dev

Import elliptic curve Certificate and Private Key into Java Keystore using java.security.KeyStore

From Dev

Import elliptic curve Certificate and Private Key into Java Keystore using java.security.KeyStore

From Dev

SecKeyRef from X.509 ASN.1 RSA Public Key in iOS

From Dev

Get ASN1 Declarations from DER

From Dev

Decode ASN1 sequence to RSA public key using Java

From Dev

How to decode non-key ASN1 data?

From Dev

How to get range of finite field and coefficients used in elliptic curve cryptography from a certificate with OpenSSL?

From Dev

How can I best check these Elliptic Curve parameters are valid?

From Dev

How to parse url parameters in key:value format?

From Dev

JAVA - I want to get key and value from below text. There is "[key] value" format

From Dev

brainpool320r1 Elliptic Curve not supported in Java Card?

From Dev

brainpool320r1 Elliptic Curve not supported in Java Card?

From Dev

Generating PublicKey from x and y values of elliptic curve point

From Dev

Getting string from variable (from imported JS) as key in object

From Dev

Get key names from key value pairs

From Dev

get key - value from dict and remove this key

From Dev

Plotting an elliptic curve in SageMath

From Dev

Elliptic curve brute forcing

From Dev

OpenSSL::PKey::RSAError (Neither PUB key nor PRIV key: nested asn1 error) while using Grocer gem on RoR app

From Dev

Get RSA Private Key in RAW format

From Dev

Get array value with specific key format in PHP

From Dev

Implode starting from key 1

Related Related

  1. 1

    Reading elliptic curve private key from file with BouncyCastle

  2. 2

    Should elliptic curve for public key generation and signature computation be the same?

  3. 3

    OpenSSL Elliptic Curve reading private key in DER form

  4. 4

    Should elliptic curve for public key generation and signature computation be the same?

  5. 5

    Generate elliptic curve key pairs (EC_KEY_generate_key) in multiple threads using OpenSSL C library

  6. 6

    Using elliptic curve Diffie-Hellman with cofactor key for generating symmetric key

  7. 7

    Generate 1024 bit RSA keypair and save public key in ASN.1 format (hex) in node.js

  8. 8

    Import elliptic curve Certificate and Private Key into Java Keystore using java.security.KeyStore

  9. 9

    Import elliptic curve Certificate and Private Key into Java Keystore using java.security.KeyStore

  10. 10

    SecKeyRef from X.509 ASN.1 RSA Public Key in iOS

  11. 11

    Get ASN1 Declarations from DER

  12. 12

    Decode ASN1 sequence to RSA public key using Java

  13. 13

    How to decode non-key ASN1 data?

  14. 14

    How to get range of finite field and coefficients used in elliptic curve cryptography from a certificate with OpenSSL?

  15. 15

    How can I best check these Elliptic Curve parameters are valid?

  16. 16

    How to parse url parameters in key:value format?

  17. 17

    JAVA - I want to get key and value from below text. There is "[key] value" format

  18. 18

    brainpool320r1 Elliptic Curve not supported in Java Card?

  19. 19

    brainpool320r1 Elliptic Curve not supported in Java Card?

  20. 20

    Generating PublicKey from x and y values of elliptic curve point

  21. 21

    Getting string from variable (from imported JS) as key in object

  22. 22

    Get key names from key value pairs

  23. 23

    get key - value from dict and remove this key

  24. 24

    Plotting an elliptic curve in SageMath

  25. 25

    Elliptic curve brute forcing

  26. 26

    OpenSSL::PKey::RSAError (Neither PUB key nor PRIV key: nested asn1 error) while using Grocer gem on RoR app

  27. 27

    Get RSA Private Key in RAW format

  28. 28

    Get array value with specific key format in PHP

  29. 29

    Implode starting from key 1

HotTag

Archive