繁体   English   中英

从两个相同的字符串获取不同的哈希

[英]Getting different hashes from two identical strings

我正在做一些散列实验。 做一个简单的测试时遇到问题。

这是我的代码:

String newWord = readFile("C:\\Users\\javip\\Desktop\\Workspace SSII\\listado-general.txt").get(5);
System.out.println(newWord);
String qwerty = "qwerty2";
System.out.println(qwerty);
System.out.println(newWord.equals(qwerty));
String sha256hex = DigestUtils.sha256Hex(newWord); 
System.out.println(DigestUtils.sha256Hex(qwerty));
System.out.println(DigestUtils.sha256Hex(sha256hex));

这是我的控制台打印的内容:

qwerty2
qwerty2
true
42ad28944380f770cf17432c3494c07c32f680173b42c3562888f096e738ef7a
ebd11cf2e1a82248edff75899ba331ffa35787c070767da0c695bba8e2be5355

我究竟做错了什么? 通过了解一些Intenet的SHA256加密器,我知道

42ad28944380f770cf17432c3494c07c32f680173b42c3562888f096e738ef7a

是使用SHA256的“ qwerty2”的正确哈希。

最后一行:

System.out.println(DigestUtils.sha256Hex(sha256hex));

有效地:

System.out.println(DigestUtils.sha256Hex(DigestUtils.sha256Hex(newWord)));

即您正在打印哈希的哈希。

暂无
暂无

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

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