Quantcast
Channel: How can I get a base64 encoded shaX on the cli? - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 6

Answer by Gilles for How can I get a base64 encoded shaX on the cli?

$
0
0

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)'

Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>