a-sit-plus / signum

Kotlin Multiplatform Crypto/PKI Library and ASN1 Parser + Encoder
https://a-sit-plus.github.io/signum/
Apache License 2.0
76 stars 6 forks source link

Private Key Parsing #174

Open nodh opened 3 weeks ago

nodh commented 3 weeks ago

Implement parsing private key from PEM representation, e.g. from this input to an object in Signum.

-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQggG4M6PesxC5/vIZz
YyXVTdNW3HgeXcdzvBes+G5cQHqhRANCAAT2M7CJBzjFcs2/GAb89tIRyB9aB8gk
Pj6QmWB94GzMT8bp/K9ivMAciGZ1uG0KMYpyrbGOGXQ7J7uXXst8Rd/l
-----END PRIVATE KEY-----
JesusMcCloud commented 3 weeks ago

@iaik-jheher just to double-check: that's a new key, works and behaves as the ephemeral key, only it's not generated, but loaded from external data. I smell boilerplate code from the future

iaik-jheher commented 3 weeks ago

Yes, sounds about right. Signer.ForPEMEncodedPrivateKey?

iaik-jheher commented 3 weeks ago

Ideally we'd want data classes for encoded private keys though...

nodh commented 3 days ago

I would really need this for verification of samples from specs. Key is defined in PKCS#1 or PKCS#8 format, e.g.:

PKCS#1:

-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIGwHU3LKj2fCxiUWB76jCnxIOJ2KAgYKbYGays8h/g+goAoGCCqGSM49
AwEHoUQDQgAET+Zr8vrF+kdr1zpjK3ufUv1fd7DS0s8Yf8/Ny3Hb4I57Sz20Zabp
brDmqFB7AmrWhdejOPHn9+Ln51i42bCdGQ==
-----END EC PRIVATE KEY-----

and PKCS#8:

-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgbAdTcsqPZ8LGJRYH
vqMKfEg4nYoCBgptgZrKzyH+D6ChRANCAARP5mvy+sX6R2vXOmMre59S/V93sNLS
zxh/z83LcdvgjntLPbRlpulusOaoUHsCataF16M48ef34ufnWLjZsJ0Z
-----END PRIVATE KEY-----
JesusMcCloud commented 2 days ago

on it

JesusMcCloud commented 2 days ago

started in #202