“Alphanumeric” hash - A-Z, 0-9

后端 未结 2 1009
盖世英雄少女心
盖世英雄少女心 2021-02-13 04:39

I\'m looking for a function that will generate an \"alphanumeric hash\". Given a source string, it produces a determinate result string that can contain any letter a-z or digit

相关标签:
2条回答
  • 2021-02-13 05:27

    How about generating your SHA256 and then Base36 encoding the result? No left over bits, no bias...

    That way you have the cryptographic strength of a proven algorithm (remember to salt and use multiple hash iterations) along with the alphanumeric representation that you need.

    0 讨论(0)
  • 2021-02-13 05:42

    If you just use those bits as they are (so that one character only has 16 possibilities), you still have your full 64 bits of entropy. If you're happy with 64 bits of entropy (which it sounds like you are), there's no reason to mind that one character has a restricted range.

    If you have some reason (aesthetics?) to prefer that all of the characters have the full range, then you can drop those 4 bits, but you'll be taking yourself down to 60 bits of entropy. If you would have been happy with 8-character passwords, then it sounds like 60 bits is also plenty.

    So whichever of those is easier should work fine.

    0 讨论(0)
提交回复
热议问题