【问题标题】:Getting different hashes from two identical strings从两个相同的字符串中获取不同的哈希值
【发布时间】:2018-07-28 06:28:32
【问题描述】:

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

这是我的代码:

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”的正确哈希。

【问题讨论】:

  • 为什么你认为双散列 newWord (DigestUtils.sha256Hex(DigestUtils.sha256Hex(newWord))) 等于单散列 qwerty (DigestUtils.sha256Hex(qwerty))?
  • 天啊...谢谢你们... 几个小时的问题,你只是对自己的代码视而不见。
  • 欢迎接受下面的正确答案。

标签: java hash sha256


【解决方案1】:

你的最后一行:

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

有效:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-21
    • 2011-07-27
    • 2011-11-12
    • 2021-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-21
    相关资源
    最近更新 更多