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:
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?
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.
Comments