|
|
Log in / Subscribe / Register

SHA256 in base64

SHA256 in base64

Posted Jan 31, 2014 22:31 UTC (Fri) by proski (guest, #104)
Parent article: OpenSSH 6.5 released

The SHA256 checksums look funny. It turns out the OpenBSD sha256 utility can output them in base64 encoding, which is nice, as it makes them as short as SHA1 checksums. Perhaps Linux sha256sum could support that mode too.


to post comments

SHA256 in base64

Posted Jan 31, 2014 22:48 UTC (Fri) by vonbrand (guest, #4458) [Link] (5 responses)

Shouldn't be to hard to hack it in...

SHA256 | base64

Posted Jan 31, 2014 23:42 UTC (Fri) by mathstuf (subscriber, #69389) [Link] (4 responses)

Hey, I thought we all preached the UNIX philosophy around here!

> sha256sum () {
> /usr/bin/sha256sum "$@" | base64 -e
> }

Isn't that good enough for you? ;)

SHA256 | base64

Posted Feb 1, 2014 4:18 UTC (Sat) by ploxiln (subscriber, #58395) [Link] (3 responses)

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

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 © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds