weidai11 / cryptopp

free C++ class library of cryptographic schemes
https://cryptopp.com
Other
4.83k stars 1.49k forks source link

Import PrivateKey from Raw Format #1169

Closed trittsv closed 1 year ago

trittsv commented 1 year ago

My goal is to convert a rawRepresentation of a P521-PrivateKey to a ECDSA<ECP, SHA256>::PrivateKey object.

What i mean with rawRepresentation:

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

Example

I have this private key (secp521r1) as rawRepresentation (shown below as hex): 00aabaf31ecb761d2c8e17a93dcf42c372b07c3221dfe00bf5991923380634f5d63ea5793451624d555c567114a53d2b4b53255557550abfe886afba802f9bddacf4

DER-Format would be: 3081ee020100301006072a8648ce3d020106052b810400230481d63081d3020101044200aabaf31ecb761d2c8e17a93dcf42c372b07c3221dfe00bf5991923380634f5d63ea5793451624d555c567114a53d2b4b53255557550abfe886afba802f9bddacf4a18189038186000401cb6eb020cc339e90daf8611d19a978e6e736bc08edeed515013f5f7445845893e2756f41b4b812da9c3de3eb5d6c7b821af1ca7080a654071a237b8d268c084b8800d35a8bf51682814ef4747fdafd46ad925b20003b026619871812de4979711d65f43501850f166223f43804a07ee3a440543e2fb587b5e401ac75d652f8614d9f2b

Is that somehow possible currently?