grokking hard

code smarter, not harder

Convert checksum between Hex and Base64 using CLI

Posted at — 2022-Dec-02

Checksums produced by SHA1, SHA2 are usually in hex format. However, there also come in base64. I just discovered a way to convert between the two.

1
2
3
4
5
6
# Convert from hex-encoded value to base64
$> echo "da3968197e7bf67aa45a77515b52ba2710c5fc34" | xxd -r -p | base64
2jloGX579nqkWndRW1K6JxDF/DQ=

$> echo "2jloGX579nqkWndRW1K6JxDF/DQ=" | base64 -d | xxd -ps
da3968197e7bf67aa45a77515b52ba2710c5fc34