|
|
Subscribe / Log in / New account

SHA256 | base64

SHA256 | base64

Posted Feb 1, 2014 4:18 UTC (Sat) by ploxiln (subscriber, #58395)
In reply to: SHA256 | base64 by mathstuf
Parent article: OpenSSH 6.5 released

I see your point, but that won't work because the output of sha256sum is hex, not binary. The best shell-utility-only pipeline would probably involve cutting that hex into pairs with '\x' before each, and then having printf output that. I don't think it would be pretty ;)


to post comments

SHA256 | base64

Posted Feb 1, 2014 5:44 UTC (Sat) by aquasync (guest, #26654) [Link]

Should be easy enough to interpose an "xxd -r -p" in there.

SHA256 | base64

Posted Feb 1, 2014 16:53 UTC (Sat) by lambda (subscriber, #40735) [Link] (1 responses)

You can instead use:
sha256sum () {
    openssl sha256 -binary "$@" | base64
}

SHA256 | base64

Posted Feb 1, 2014 17:04 UTC (Sat) by lambda (subscriber, #40735) [Link]

By the way, my version of the base64 command defaults to encoding, while it looks like the one mentioned above defaults to decoding; and they don't take the same options so you can't write something portable to both (mine doesn't have the -e option).

If we're already using the openssl command, we can work around that difference with:

sha256sum () {
    openssl sha256 -binary "$@" | openssl base64
}


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds