LoginSignup
2
1

More than 3 years have passed since last update.

【Go】SHA-1で文字列をハッシュ化

Last updated at Posted at 2020-02-04

SHA-1ハッシュ関数で文字列をハッシュ化

ちなみにパスワードとかのハッシュ化にこれを用いるのは推奨されてない


package main

import (
    "crypto/sha1"
    "encoding/hex"
    "fmt"
    "io"
)

func main() {
    str := HashedBySha1("あかさたな")
    fmt.Print(str) // d6c286cf2c63d5c718eb6c51e26bfc79d11d332c
}

func HashedBySha1(str string) string {
    sha1 := sha1.New()
    io.WriteString(sha1, str)
    return hex.EncodeToString(sha1.Sum(nil))
}

The Go Playground

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1