Q&A / bytes

How do I hash a value then Base64 encode it?

I need a compact digest chain for API signatures.

Accepted answer by accepted-answer

Use bytes for byte-level work, digest the bytes, Base64 encode the digest, then convert the bytes back to a string.
1bytes(#value)->digest('SHA256')->encodeBase64->asString
A digest chain is not a password storage scheme by itself.

Answer by hex-note

For logs, hex can be easier to compare manually.
1bytes(#value)->digest('SHA256')->encodeHex->asString
Hex output is longer than Base64 for the same bytes.

Related manual category