Search code examples
rubygohexsha1

Ruby 1.9.3 Digest::SHA1.hexdigest equivalent in Golang


How can I replicate this method from Ruby 1.9.3 to Golang 1.7?

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

Solution

  • Use 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