Was wondering why there is no straightforward way of using ed25519 keys for encryption.
Then I found this: https://github.com/indutny/elliptic/issues/108
There it is stated that it's unlike RSA not recommendable for this purpose - one should rather derive a Symmetric key from diffie-hellman style shared secret.
It is rather used for signing. But if signing works like this:
hash = doHash(message) signature = doAsymmetricEncrypt(hash, privateKey) hash == doAsymmetricDecrypt(signature, publicKey) // true
I would assume it should also work in this direction.
encryptedToken = doAsymmetricEncrypt(token, publicKey) token = doAsymmetricDecrypt(encryptedToken, privateKey)
My current understanding of the relevant matter boils down to:
- asymmetric cryptography works in both directions: encrypt with private key -> decrypt with public key & encrypt with public key -> decrypt with private key
- ed25519 private key is just a random 256-bit number
- the public key may be unambiguously derived by projecting the private key number over the curve25519
- ed25519 actually means the version as DSA in combination with SHA-512
So I would assume that when I have the 32 bytes for the private key and know that it is exactly such key. I should be able to just use it in any context regardless of using it as signature or encryption algorithm.