Perl has a base64 module (in the base distribution since 5.7.1).
echo foo | sha1sum | \
perl -MMIME::Base64 -ne '/^([[:xdigit:]]+)/ and print encode_base64(pack("H*",$1))'
If you have the Digest::SHA
module (in the base distribution since 5.9.3), or the older Digest::SHA1
module, you can do the whole computation in perl. As of perl 5.10.1, b64digest
doesn't pad the base64 output; if you need padding the easiest way is to use MIME::Base64
.
perl -MDigest::SHA -e 'print Digest::SHA->new(1)->addfile(*STDIN)->b64digest'
perl -MMIME::Base64 -MDigest::SHA \
-le 'print encode_base64(Digest::SHA->new(1)->addfile(*STDIN)->digest)'