Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

The following command works for encrypting stdin using echo:

echo "abc" | openssl enc -base64

This command also works for substituting characters in stdin using cat:

cat | sed 's/a/b/g'

However, the following command, which should encrypt stdin using cat does not meet my needs, because it doesn't display the encoded value every time I hit return.

cat | openssl enc -base64

How do I encrypt stdin on-the-fly using cat?

share|improve this question
1  
"Don't work" is not a very good problem description. –  David Schwartz Apr 23 '13 at 4:09

2 Answers 2

If you type

cat | openssl enc -base64

and then press Ctrl + D then it will encode everything you just typed.

share|improve this answer
    
While that works, I need a continues result. IE I keep typing and every time I hit return, I get an encoded value out –  nick Apr 23 '13 at 6:06
    
@nick: If you want to get satisfactory answers, you should edit your question to add details like this. –  Scott Aug 2 '13 at 22:33
1  
@nick: to be clear, every time you press enter you want an encoded value just for that line of text, or for the entire body of text you've entered? –  Nathan Nov 4 '13 at 20:08

First of all, you (just about) never need to use cat | or cat one_file |.  For example, your sed example works fine as

sed 's/a/b/g'

So my first suggestion is that you try

openssl enc -base64

without the cat.

But, honestly, I don’t expect that to work. You may need to get a little fancier:

while read x
do
      echo "$x" | openssl enc -base64
done

Note that this runs a new openssl command for each line of input, so this might not give the same results as the same input run through a single invocation of openssl.

share|improve this answer

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.