Add base-64 encoding support to SHA1
commit6e4b88c0706a637948ef9438217c47fc7ff266c0
authorRick Lavoie <rlavoie@fb.com>
Wed, 8 Jul 2020 21:07:53 +0000 (8 14:07 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Wed, 8 Jul 2020 21:22:07 +0000 (8 14:22 -0700)
treea1d5960315f69536b98ae7677f6472ee46774efe
parentd46bd55f4cb5a78af40774162c1761719eb0ae9f
Add base-64 encoding support to SHA1

Summary:
SHA1's toString method encodes it using base-16, which is the typical
representation for a SHA1 hash. However in some cases we want a more
compact string representation (the particular format may not
matter). We can use base-64 for this, as its the most compact (power
of 2) representation while keeping the output relatively readable. Add
a toStringBase64 method to SHA1. Encoding a SHA1 hash in base-64
requires 27 characters. However 27 base-64 characters can encode 162
bits, so there's 2 unused bits in the encoding. This can be handy to
encode a little bit extra data directly into the hash, so provide a
mechanism to do so.

Reviewed By: jjgriego

Differential Revision: D22422725

fbshipit-source-id: f107451866152690b5cb395c964dd61710b447b6
hphp/util/sha1.h