Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenSSL Command Line Tool: "-in" argument from string

How can I trick the -in argument of the OpenSSL command line tool in order to get data from string instead a file?

Normally, I could use echo command to do it:

echo 'test string 1' | openssl enc -aes-256-cbc -a -salt -pass pass:mypassword

Is there a way I can do it without echo and pipe? Similar to the -pass pass: argument?

Thanks in advance!

like image 497
TCB13 Avatar asked Jan 20 '12 02:01

TCB13


2 Answers

If your shell is bash and your OS supports it, you can use process substitution:

openssl enc -in <(echo 'test string 1') -aes-256-cbc -a -salt -pass pass:mypassword
like image 64
Nemo Avatar answered Oct 03 '22 06:10

Nemo


I found a way to go around this! Instead of passing everything before and since openssl has an interactive mode, it's possible to run the command without input:

openssl enc -aes-256-cbc -a -salt -pass pass:mypassword

And OpenSSL will be waiting for data to encrypt. This can be also useful for streams!

Then type in the string or data you want to encrypt and send a EOT (End of Transmission) in Terminal is usual ^D Control+D it it will output to stdout the encrypted string!

Hope this may help someone some day!

like image 27
TCB13 Avatar answered Oct 03 '22 06:10

TCB13