How to use ssh-rsa public key to encrypt a text?
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Techno Intrigue Looping
--
Chapters
00:00 How To Use Ssh-Rsa Public Key To Encrypt A Text?
00:46 Accepted Answer Score 108
01:28 Answer 2 Score 4
01:41 Answer 3 Score 1
02:01 Answer 4 Score 0
02:28 Thank you
--
Full question
https://superuser.com/questions/576506/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#encryption #openssl
#avk47
ACCEPTED ANSWER
Score 108
It's possible to convert your ssh public key to PEM format(that 'openssl rsautl' can read it):
Example:
ssh-keygen -f ~/.ssh/id_rsa.pub -e -m PKCS8 > id_rsa.pem.pub
Assuming 'myMessage.txt' is your message which should be public-key encrypted.
Then just encrypt your message with openssl rsautl and your converted PEM public-key as you would normally do:
openssl rsautl -encrypt -pubin -inkey id_rsa.pem.pub -ssl -in myMessage.txt -out myEncryptedMessage.txt
The result is your encrypted message in 'myEncryptedMessage.txt'
To test your work to decrypt the with Alice' private key:
openssl rsautl -decrypt -inkey ~/.ssh/id_rsa -in myEncryptedMessage.txt -out myDecryptedMessage.txt
ANSWER 2
Score 4
Give a try to ssh-vault it uses ssh-rsa public keys to encrypt "create a vault" and the ssh-rsa private key to decrypt "view content of the vault"
ANSWER 3
Score 1
See https://www.bjornjohansen.com/encrypt-file-using-ssh-key. The idea is to generate a single-use symmetric key that is short enough to be encrypted using SSH public key. Then, you use the symmetric key to enrypt your text, and send both the encrypted text and the encrypted key to the recipient.
ANSWER 4
Score 0
NecroThreading a bit, but I had the same issue and catacomb did not quite cover it, so I ended up making my own variation. Also, I found that dealing with file redirects a bit confusing for my end-users, and the need to download the script beforehand a bit tedious, so my version wraps itself to make an auto-extractible file so the end-user has the easiest time getting the file.
It can be found at https://github.com/BaptisteRichard/rsaCrypt
Please advise that my users are on gitlab and not github so I tweaked that a bit, but it could easily be retrofitted. MR are welcome