简体   繁体   English

将雪花 MD5 匹配到 Python MD5

[英]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.我正在尝试将来自 Snowflake md5_number_lower64的 MD5 output 与相同字符串的 ZA7F5F35426B927411FC9231B56382173 中的 MD5 output 匹配。

What's the code to pull this off?什么是代码来解决这个问题?

A quick example (from a teammate) to pull this off.一个简单的例子(来自队友)来实现这一点。 In Python:在 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.返回一个 64 位无符号 integer,它表示消息摘要的低 64 位。 This representation is useful for maximally efficient storage and comparison of MD5 digests.这种表示对于 MD5 摘要的最大有效存储和比较很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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