dougaojue8185 2018-08-12 05:15
浏览 233

SHA1秘密编码,等效于PHP hash_hmac

I have the following PHP function

public function encodePassword($raw, $salt)
    {
        return hash_hmac('sha1', $raw . $salt, $this->secret);
    }

which I need to translate to Go. I found the following example, but it doesn't involve secret key. https://gobyexample.com/sha1-hashes

How can I create a function in Go, that produces exactly same result as PHP's hash_hmac?

Update: After Leo's answer, found this resource with hmac examples in many languages: https://github.com/danharper/hmac-examples. Can be useful to somebody.

  • 写回答

2条回答 默认 最新

  • dongsechuan0535 2018-08-12 06:52
    关注

    Something like this:

    import "crypto/sha1"
    import "crypto/hmac"
    
    func hash_hmac_sha1(password, salt, key []byte) []byte {
        h := hmac.New(sha1.New, key)
        h.Write(password)
        h.Write(salt)
        return h.Sum(nil)
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器