Convert hex to base64

@chrillek

As discussed in another thread, “Hello World” and “Hello world” are different things. Hugo’s crypto functions are doing the right thing, and our documentation is correct.

I’ll add something to the md5, sha1, and sha256 descriptions to indicate that the return value is hex (as shown in the examples). Other than that, there’s not a whole lot to explain.

@jhvanderschee

TLDR: I can’t think of way to do this that isn’t… convoluted, and even then I’m not sure it’s possible.

Hugo’s md5, sha1, and sha256 crypto functions encode the checksum to hex, and we do not have a “hex2bin” function as shown in your PHP example.

In comparison, Hugo’s hmac crypto function includes an optional encoding argument, either hex (default) or binary. It would be convenient if md5, sha1, and sha256 had signatures such as…

sha1 INPUT [ENCODING] 

…where ENCODING is one of hex (default), binary, or base64. And add base64 to the hmac encodings as well. I’m waffling on the binary option, though it would provide input for future encoding functions without having to add those options to the crypto functions.

The signature above is backwards compatible.

Or we could look at a hex2bin function, but I can’t remember a request/need for this functionality outside of your example.

2 Likes