Home » Questions » Computers [ Ask a new question ]

How can I encrypt a string in the shell?

How can I encrypt a string in the shell?

Can I encrypt a message (string) using a public key at the command prompt? Also, how can I decrypt the result afterwards?

Asked by: Guest | Views: 80
Total answers/comments: 1
Guest [Entry]

"Generate a private/public key pair

$ openssl genrsa -out rsa_key.pri 2048; openssl rsa -in rsa_key.pri -out rsa_key.pub -outform PEM -pubout

Encrypt the string using public key, and store in a file

$ echo ""stockexchange.com"" | openssl rsautl -encrypt -inkey rsa_key.pub -pubin -out secret.dat

Un-encrypt using private key

$ string=`openssl rsautl -decrypt -inkey rsa_key.pri -in secret.dat `; echo $string
stockexchange.com"