简体   繁体   English

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

[英]Getting different hashes from two identical strings

I'm making some experiments with hashing. 我正在做一些散列实验。 I'm getting a problem while doing a simple test. 做一个简单的测试时遇到问题。

This is my code: 这是我的代码:

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));

And here it is what my console prints: 这是我的控制台打印的内容:

qwerty2
qwerty2
true
42ad28944380f770cf17432c3494c07c32f680173b42c3562888f096e738ef7a
ebd11cf2e1a82248edff75899ba331ffa35787c070767da0c695bba8e2be5355

What am I doing wrong? 我究竟做错了什么? I know by comprobation in some SHA256 encrypters of Intenet that 通过了解一些Intenet的SHA256加密器,我知道

42ad28944380f770cf17432c3494c07c32f680173b42c3562888f096e738ef7a 42ad28944380f770cf17432c3494c07c32f680173b42c3562888f096e738ef7a

is the correct hash for "qwerty2" using SHA256. 是使用SHA256的“ qwerty2”的正确哈希。

Your last line: 最后一行:

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

is effectively: 有效地:

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

ie you're printing the hash of the hash. 即您正在打印哈希的哈希。

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

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