压缩哈希输出(从十六进制到 "higher" 表示)

Compress hash output (from hex to "higher" representation)

我有一个 40 个字符长的 SHA1 值,它存储在 InnoDB table 的索引列中。为了缩短索引,我希望它是 "compressed" 而不会增加碰撞的风险。

<?php

$a = "875e5d6959da75400c837a79ecca23d79b40e7a5";

$b = base_convert($a, 16, 36);

echo $b; // ft92zicmcfks08088wk0oow44oso8gk

?>

这个方案可以吗?为什么我不能转换为base64,它给了我以下警告:

Warning: base_convert(): Invalid "to base" (64) in...

因为根据 base_convert

的手册

... tobase have to be between 2 and 36, inclusive. Digits in numbers with a base higher than 10 will be represented with the letters a-z, with a meaning 10, b meaning 11 and z meaning 35. The case of the letters doesn't matter, i.e. number is interpreted case-insensitively.