Say you have someones public key at pubkey.pub
:
$ echo "potato" | openssl rsautl -encrypt -pubin -inkey <(ssh-keygen -f pubkey.pub -e -m PKCS8) -ssl | openssl base64
Now send the result to them, e.g. message.txt
, and they have their private key at ~/.ssh/id_rsa
$ cat message.txt | openssl base64 -d | openssl rsautl -decrypt -inkey ~/.ssh/id_rsa