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 = doAsymetricEncrypt(hash, privateKey) hash == doAsymetricDecrypt(signature, publicKey) //true
So I would assume it should also work in this direction.
encryptedToken = doAsymetricEncrypt(token, publicKey) token = doAsymetricDecrypt(encryptedToken, privateKey)
My current understanding of the relevant matter boils down to:
- asymetric 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 256bit number
- the public key may be unambigously 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 32bytes 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.