dongxibeng5324 2017-09-16 15:30
浏览 36
已采纳

去郎SHA3-256提供无效的输出? [关闭]

I am facing strange results fo go SHA3-256 function: here is source code

import (
    "golang.org/x/crypto/sha3"
    "encoding/hex"
)

func main() {
    pub, _ := hex.DecodeString("c342dbf7cdd3096c4c3910c511a57049e62847dd5030c7e644bc855acc1fd626")
    h := sha3.Sum256(pub[:])
    fmt.Printf("SHA3 %x
", h)
    // expected: b32562e67d3ea44ba1367ce134caac49fd305b24cde6716ad3857ac682576379
    // received: 8a3ccc097f854811f4c49346da9c3bd1745d087ed539fa7817960f3e0ed8a44f
}

I verified result on couple of online converters, they all give same result, different from mine.

  • 写回答

1条回答 默认 最新

  • dtye7921 2017-09-16 17:12
    关注

    You are assuming that the online converters that you've tested perform hexadecimal decoding. They don't; they just take the ASCII/UTF-8/whatever value of the string and use that, i.e. they hash the text.

    This can be easily observed by inputting your c342... string and then inputting hello. Both will work, while hello obviously doesn't contain hexadecimals. Another way is to start with an uppercase C instead of c, which will also return a different result, while the hexadecimal decoding should return an identical byte array and thus hash.

    And a small Java application does indeed confirm your value of:

    8a3ccc097f854811f4c49346da9c3bd1745d087ed539fa7817960f3e0ed8a44f
    

    Note that most if not all online tools are basically hobby projects by amateur cryptographers. Expect all kind of encoding / decoding issues, errors and uncertainties in the implementation. If you want to test your implementation, use the official NIST test vectors.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog