最多20个字符的字母数字输出哈希算法 [英] Hash algorithm with alphanumeric output of 20 characters max

查看:145
本文介绍了最多20个字符的字母数字输出哈希算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个散列算法,输出一个最长为20个字符的字母数字字符串。对于字母数字,我的意思是 [a-zA-Z0-9]



输入是 UUID s的规范形式(例如 550e8400-e29b -41d4-a716-446655440000



另一种方法是将SHA1或MD5散列转换为具有这些限制的字符串? / b>

谢谢。

编辑

不需要加密安全。碰撞使数据不准确,但如果它们偶尔发生,我可以忍受它。



编辑2



我不知道截断MD5或SHA1是否会使碰撞频繁发生。现在我想知道是否最好将20个字符截断为MD5值或SHA1值。 解决方案

你不需要从GUID的散列。使用良好的散列函数,散列的任何部分的不可预测性都与该部分的大小成正比。如果你愿意,你可以编码它的基地32,而不是标准的十六进制基地16.记住,这不会显着改善每个字符的熵(只有25%)。



<对于非加密用途,截断MD5,SHA1或SHA2无关紧要。在熵方面也没有明显的不足。

I need an hash algorithm that outputs an alphanumeric string that is max 20 characters long. For "alphanumeric" I mean [a-zA-Z0-9].

Inputs are UUIDs in canonical form (example 550e8400-e29b-41d4-a716-446655440000)

In alternative is there a way to convert a SHA1 or MD5 hash to a string with these limitations?

Thanks.

EDIT

Doesn't need to be cryptographically secure. Collisions make data inaccurate, but if they happen sporadically I can live with it.

EDIT 2

I don't know if truncating MD5 or SHA1 would make collisions happen too often. Now I'm wondering if it's better to truncate to 20 chars a MD5 value or a SHA1 value.

解决方案

Just clip the characters you don't need from the hash of the GUID. With a good hash function, the unpredictability of any part of the hash is proportional to the part's size. If you want, you can encode it base 32 instead of the standard hex base 16. Bear in mind that this will not significantly improve entropy per character (only by 25%).

For non-cryptographic uses, it does not matter whether you truncate MD5, SHA1 or SHA2. Neither has any glaring deficiencies in entropy.

这篇关于最多20个字符的字母数字输出哈希算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆