OpenSSL Ed25519 密钥根据 RFC8410 进行编码:
OneAsymmetricKey ::= SEQUENCE {
version Version,
privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
privateKey PrivateKey,
attributes [0] IMPLICIT Attributes OPTIONAL,
...,
[[2: publicKey [1] IMPLICIT PublicKey OPTIONAL ]],
...
}
PrivateKey ::= OCTET STRING
PublicKey ::= BIT STRING
For the keys defined in this document, the private key is always an
opaque byte sequence. The ASN.1 type CurvePrivateKey is defined in
this document to hold the byte sequence. Thus, when encoding a
OneAsymmetricKey object, the private key is wrapped in a
CurvePrivateKey object and wrapped by the OCTET STRING of the
"privateKey" field.
CurvePrivateKey ::= OCTET STRING
为了进一步澄清,有一个示例密钥:
30 2E 02 01 00 30 05 06 03 2B 65 70 04 22 04 20
5F E5 F1 D9 02 D6 B4 2E 55 B6 E4 E4 01 E9 87 C3
F2 BC 7F 95 D3 31 88 86 3D E9 17 60 B7 D5 84 92
30 2E => SEQUENCE of 3 Elements having length of 46
02 01 00 => INTEGER of length 1 being 00 (Version)
30 05 => SEQUENCE of 1 Element having length of 5
06 03 2B 65 70 => OBJECT IDENTIFIER of length 3 being 2B 65 70 (PrivateKeyAlgorithmIdentifier)
04 22 => OCTET STRING of Length 34
04 20 => OCTET STRING of Length 32
Value of the real OCTET STRING (PrivateKey):
5F E5 F1 D9 02 D6 B4 2E 55 B6 E4 E4 01 E9 87 C3
F2 BC 7F 95 D3 31 88 86 3D E9 17 60 B7 D5 84 92