You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
510 B
Go
33 lines
510 B
Go
package crypto
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"crypto/sha1"
|
|
"crypto/sha256"
|
|
"fmt"
|
|
)
|
|
|
|
// MD5 回傳md5加密
|
|
func MD5(v string) string {
|
|
h := md5.New()
|
|
h.Write([]byte(v))
|
|
bs := h.Sum(nil)
|
|
return fmt.Sprintf("%x", bs)
|
|
}
|
|
|
|
// SHA1 回傳sha1加密
|
|
func SHA1(v string) string {
|
|
h := sha1.New()
|
|
h.Write([]byte(v))
|
|
bs := h.Sum(nil)
|
|
return fmt.Sprintf("%x", bs)
|
|
}
|
|
|
|
// SHA256 回傳sha256加密
|
|
func SHA256(v string) string {
|
|
h := sha256.New()
|
|
h.Write([]byte(v))
|
|
bs := h.Sum(nil)
|
|
return fmt.Sprintf("%x", bs)
|
|
}
|