简体   繁体   English

哈希密码

[英]hashed password

I have been playing around with the code found here . 我一直在玩这里找到的代码。 I'm getting things like 我正在得到像

UKepQT7tW8mGtOJzNaLV2X+Ij/E=

when I view the hashed password using 当我使用查看哈希密码时

String t = base64EncoderDecoder.encodeAsString(f.generateSecret(spec).getEncoded());

for my hashed password. 输入我的哈希密码。 Should it have symbols like +/= ? 是否应具有+ / =之类的符号? Also I expected the hash to be longer. 我也希望哈希更长。 Did I screw something up? 我搞砸了吗?

Should it have symbols like +/= ? 是否应具有+ / =之类的符号?

Well, according to what should have been the first Google result (the Wikipedia article on Base64 encoding ), + and / are valid symbols that are mapped to 62 and 63 respectively. 好吧,根据第一个Google结果(根据Wikipedia文章有关Base64编码的说明 ), +/是有效的符号,分别映射到62和63。 = is a padding character. =是填充字符。

Also I expected the hash to be longer. 我也希望哈希更长。

Why? 为什么? It's just a consequence of the encoding method you're using. 这只是您使用的编码方法的结果。 Encoding something in base 16 will take 50% more characters (since it takes 1 character per 4 bits, instead of 1 character per 6 bits). 以16为底进行编码将多占用50%的字符(因为每4位占用1个字符,而不是每6位占用1个字符)。 From the very reference you cite: 从引用中可以引用:

 // SHA-1 generates 160 bit hashes, so that's what makes sense here 

160 bits results in a 27 character Base64 encoding (160/6 ~= 27), which is what you have, so it seems reasonable to me. 160位的结果是27字符的Base64编码(160/6〜= 27),这正是您所拥有的,因此对我来说似乎很合理。

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

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