Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

migrated from Aug 10 '09 at 10:26

This question came from our site for professional and enthusiast programmers.

Another option is openssl:

# generate a 2048-bit RSA key and store it in key.txt
openssl genrsa -out key.txt 2048

# encrypt "hello world" using the RSA key in key.txt
echo "hello world" | openssl rsautl -inkey key.txt -encrypt >output.bin

# decrypt the message and output to stdout
openssl rsautl -inkey key.txt -decrypt <output.bin
share|improve this answer
+1 for openssl since it's more commonly installed than gpg is – Doug Harris Aug 10 '09 at 14:08

If you have gpg installed, this is an industrial-strength encryption method.

gpg --encrypt -r >tempfile

Type data at the console and press Ctrl+D to end the text. This will give you encrypted data in tempfile. To decrypt:

gpg --decrypt <tempfile

You will need the passphrase for to decrypt the message.

share|improve this answer

man crypt(1)


crypt implements a one-rotor machine designed along the lines of the German Enigma, but with a 256-element rotor. Methods of attack on such machines are widely known, thus crypt provides minimal security.

But it's OK for demonstration purposes.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.