I have this command within a shell script
echo -n $2 | openssl rsautl -encrypt -pubin -inkey $1
where $2 stands for a string argument and $1 is the public key that is to be used.
I would like the output to be the equivalent base64 string of the binary encryption, but adding | base64 at the end of the command does not seem to work (probably because the encrypted output contains null characters and cuts the base64 input short.
Is it possible to accomplish the base64 encoding without creating a cyphertext intermediary file to dump the data in the first place?
For example, I would like to make
echo -n "asdf" | openssl rsautl -encrypt -pubin -inkey key.pub.pem
to output something along the lines of
stWslUhRRCk/bZveABLG7fA8z9ZkYc+lBBd5QhvyGNwuI2T5v2sk8aJL3X3Xerrogsu35Wk5O839..........
instead of binary unreadable characters without requiring an intermediate file to be created (I truncated the output for brevity)