【问题标题】:Ruby 1.9.3 Digest::SHA1.hexdigest equivalent in Golang [closed]Golang 中的 Ruby 1.9.3 Digest::SHA1.hexdigest [关闭]
【发布时间】:2017-12-28 17:23:31
【问题描述】:

如何将此方法从 Ruby 1.9.3 复制到 Golang 1.7?

require 'digest/sha2'
text = Digest::SHA1.hexdigest("Hello world")

【问题讨论】:

标签: ruby go hex sha1


【解决方案1】:

使用crypto/sha1

package main

import (
    "crypto/sha1"
    "fmt"
)

func main() {
    s := sha1.New()
    s.Write([]byte("Hello world"))
    fmt.Printf("%x", s.Sum(nil))
}

playground

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-28
    • 2013-05-22
    • 2012-07-29
    • 1970-01-01
    • 2015-07-09
    • 1970-01-01
    • 1970-01-01
    • 2017-08-16
    相关资源
    最近更新 更多