java - 散列密码

标签 java cryptography passwords

我一直在研究找到的代码 here 。我得到类似的东西

UKepQT7tW8mGtOJzNaLV2X+Ij/E=

当我使用

查看哈希密码时
String t = base64EncoderDecoder.encodeAsString(f.generateSecret(spec).getEncoded());

我的哈希密码。它应该有像 +/= 这样的符号吗?我还预计哈希值会更长。我搞砸了什么吗?

最佳答案

Should it have symbols like +/= ?

嗯,根据第一个 Google 结果( Wikipedia article on Base64 encoding ),+/ 是分别映射到 62 和 63 的有效符号。 = 是一个填充字符。

Also I expected the hash to be longer.

为什么?这只是您使用的编码方法的结果。以 16 为基数进行编码将多使用 50% 的字符(因为每 4 位需要 1 个字符,而不是每 6 位需要 1 个字符)。从您引用的引用文献来看:

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

160 位会产生 27 个字符的 Base64 编码 (160/6 ~= 27),这就是您所拥有的,所以对我来说这似乎是合理的。

关于java - 散列密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11372611/

相关文章:

java - 将工作委托(delegate)给其他人的单元测试类的最佳方法是什么?

objective-c - 如何在 Objective C 中创建 PKCS12

c# - CSharp 中的密码代码类似于 Go 中的代码(AES、CFB、XorKeyStream)

c# - 密码扩展——一种减轻 CPU 泛滥的方法

java - 在java中生成有很多限制的随 secret 码

java.sql.SQLException : Invalid column index using jdbcTemplate 异常

java - 如何在 Android Lollipop 中使用 Base64.getUrlEncoder

java - eclipse /Java : easy way to consolidate classes source code without individual copy/paste?

security - 使用密码和种子进行加密时哪种过程更安全

hash - 在不保存为明文的情况下实现大量密码更改的最佳方法?