Created
July 4, 2019 23:15
-
-
Save willnix/25a0b56e59fdd67a0d2b8923ee38999c to your computer and use it in GitHub Desktop.
Python version of hashUnencodedChars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import hashlib | |
def hash_unencoded_chars(s: str) -> hashlib.sha256: | |
""" hash_unencoded_chars - emulates com.google.common.hash.Hashing.sha256().hashUnencodedChars(s) | |
Google's java library guava comes with the hashUnencodedChars function | |
which yields different results than most other language's hashing functions. | |
This function should be compatible. | |
""" | |
b = s.encode('utf-16-le') | |
return hashlib.sha256(b) | |
if __name__ == "__main__": | |
print(hash_unencoded_chars('String').hexdigest()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment