github.com/sereiner/library@v0.0.0-20200518095232-1fa3e640cc5f/security/md5/md5.go (about) 1 package md5 2 3 import ( 4 "crypto/md5" 5 "encoding/hex" 6 ) 7 8 // Encrypt MD5加密 9 func Encrypt(s string) string { 10 return EncryptBytes([]byte(s)) 11 } 12 func EncryptBytes(buffer []byte) string { 13 md5Ctx := md5.New() 14 md5Ctx.Write(buffer) 15 cipherStr := md5Ctx.Sum(nil) 16 return hex.EncodeToString(cipherStr) 17 }