MD5哈希和Base64编码 [英] MD5 Hash and Base64 encoding

查看:648
本文介绍了MD5哈希和Base64编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我c将其Base64的使用有一个32字符的字符串(MD5哈希),我带$ C $,有什么恩codeD字符串的长度maximun?

If I have a 32 character string (an MD5 hash) and I encode it using Base64, what's the maximun length of the encoded string?

推荐答案

这是MD5值为始终22(有用)字符长为Base64表示法。编码MD5哈希时,使总数达到24个字符的Base64许多算法也将追加填充的2个字符。填充增加了有用的信息,并且可以被丢弃。只有前22个字符无所谓。

An MD5 value is always 22 (useful) characters long in Base64 notation. Many Base64 algorithms will also append 2 characters of padding when encoding an MD5 hash, bringing the total to 24 characters. The padding adds no useful information and can be discarded. Only the first 22 characters matter.

下面的原因:

这是MD5哈希值是一个128位的值。在Base64编码字符串的每个字符包含6比特信息,因为有人物64个可能值,这需要2 6权力在每一个角色达到64. 6比特的信息,21个字符具有信息126位,和22个字符包含的信息132位。由于128位不能在21个字符适合但在22个字符符合(一点点剩余空间),一个128位的值将始终被重新为Base64 psented为22个字符$ P $。

An MD5 hash is a 128-bit value. Every character in a Base64 string contains 6 bits of information, because there are 64 possible values for the character, and it takes 6 powers of 2 to reach 64. With 6 bits of information in every character, 21 characters has 126 bits of information, and 22 characters contains 132 bits of information. Since 128 bits cannot fit within 21 characters but does fit within 22 characters (with a little room to spare), a 128-bit value will always be represented as 22 characters in Base64.

在填充的说明:

我上面有很多Base64编码算法编码MD5值时,添加一些填充字符提及。这是因为重新Base64编码presents 3个字节的信息为4个字符。自的MD5有16个字节的信息,许多Base64编码算法追加==,以指定的16个字节的输入是短的3的下一个倍数,这将是18个字节的2个字节。这2个等号任何添加任何信息的字符串,可以存放时被丢弃。

I mentioned above that many Base64 encoding algorithms add a couple of characters of padding when encoding an MD5 value. This is because Base64 represents 3 bytes of information as 4 characters. Since MD5 has 16 bytes of information, many Base64 encoding algorithms append "==" to designate that the input of 16 bytes was 2 bytes short of the next multiple of 3, which would have been 18 bytes. These 2 equal signs add no information whatsoever to the string, and can be discarded when storing.

这篇关于MD5哈希和Base64编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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