简体   繁体   中英

Match Snowflake MD5 to Python MD5

I'm trying to match the MD5 output from Snowflake md5_number_lower64 to the MD5 output in Python for the same string.

What's the code to pull this off?

A quick example (from a teammate) to pull this off. In Python:

import hashlib
def md5_number_lower64(msg):
    return int.from_bytes(hashlib.md5(msg.encode('utf-8')).digest()[8:], 'big')

returns:

$ print(md5_number_lower64('Snowflake'))
> 9203306159527282910`

which matches Snowflake's result:

select md5_number_lower64('Snowflake');
-- 9203306159527282910

Docs:

Returns a 64 bit unsigned integer that represents the lower 64 bits of the message digest. This representation is useful for maximally efficient storage and comparison of MD5 digests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM