Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to encrypt a bunch of strings using openssl. How do I pass plaintext in console to openssl (instead of specifying input file which has plaintext).

openssl man page has only these two options related to input/output:

-in <file>     input file
-out <file>    output file

Here is what I have tried so far:

This works fine,

openssl aes-256-cbc -a -K 00000000000000000000000000000000 -iv 00000000000000000000000000000000 -in plain.txt -out encrypted.txt

If I omit the -out parameter I get encrypted string in console,

openssl aes-256-cbc -a -K 00000000000000000000000000000000 -iv 00000000000000000000000000000000 -in plain.txt

But If I omit both -in and -out, I get an error - unknown option 'Encrypt ME',

openssl aes-256-cbc -a -K 00000000000000000000000000000000 -iv 00000000000000000000000000000000 "Encrypt ME"
share|improve this question

2 Answers 2

up vote 3 down vote accepted

Use this:

user@host:~$ echo "my string to encrypt" | openssl aes-256-cbc -e -a -K 00000000000000000000000000000000 -iv 00000000000000000000000000000000
a7svR6j/uAz4kY9jvWbJaUR/d5QdH5ua/vztLN7u/FE=
user@host:~$ echo "a7svR6j/uAz4kY9jvWbJaUR/d5QdH5ua/vztLN7u/FE=" | openssl aes-256-cbc -d -a -K 00000000000000000000000000000000 -iv 00000000000000000000000000000000
my string to encrypt

Or you could use command substitution:

user@host:~$ openssl aes-256-cbc -a -K 00000000000000000000000000000000 -iv \
00000000000000000000000000000000 -in <(echo "my string to encrypt") -out encrypted.txt
share|improve this answer
    
Thanks chaos. 'command substitution' is what I was looking for. –  Nitish Aug 8 at 9:37

what about

echo encrypt Me | openssl aes-256-cbc -a -K 00000000000000000000000000000000 -iv 00000000000000000000000000000000

If your concerne is that a ps will show the plain text 'encrypt me', then you'd better sitck with file, beeing carefull to erase them.

share|improve this answer
    
Thanks. I am not concerned about command history but I will keep that in mind. –  Nitish Aug 8 at 9:36

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.