go-piv / piv-go

Keys and certificates for YubiKeys, written in Go
Apache License 2.0
366 stars 65 forks source link

Private key decryption on Yubikey by ECDSA #127

Closed zhelnov closed 1 year ago

zhelnov commented 1 year ago

Hi!

I'm playing with Yubikey and this library a bit, my goal is to be able to generate key pair on Yubikey and then encrypt some message with public key anywhere and decrypt this data only on Yubikey. I achieved this using RSA keys, but hit a snag with the length of message that RSA able to encrypt (RSA allows to encrypt message no longer than key length minus some 11 meta bytes as i remember). I need to encrypt/decrypt big messages, so i switched to ECDSA (P256), but noticed that here https://github.com/go-piv/piv-go/blob/master/piv/key.go#L1092 only RSA key struct has Decrypt() implementation.

I'd like to know:

Thank you.

ericchiang commented 1 year ago

Hey Mykyta,

Take a look at: https://cryptobook.nakov.com/asymmetric-key-ciphers/ecc-encryption-decryption

Specifically:

The elliptic curve cryptography (ECC) does not directly provide encryption method.

It also sounds like age is exactly what you're after: https://github.com/FiloSottile/age

Broadly, there's a big difference between proving possession of a private key by decrypting small bits of information during a handshake, and encrypting large amounts of data to a sender. Protocols generally bootstrap symmetric keys to achieve the later, though there are a lot of opportunities to get subtle things wrong.

Good luck! Going to close out since it sounds like this isn't an issue with this package.

zhelnov commented 1 year ago

Huge thanks!