先从个简单点的,也是用的比较多MD5加密开始,很少说直接上代码html
package sign import "crypto/md5" type MD5Client struct { } var MD5 = MD5Client{} func (this *MD5Client) Encrypt(plantext []byte) []byte { result := md5.Sum(plantext) return result[:] } /* 给要加密的信息加把盐 */ func (this *MD5Client) EncryptWithSalt(plantext []byte,salt []byte) []byte { hash := md5.New() hash.Write(plantext) hash.Write(salt) return hash.Sum(nil) }
加密后的获得长度为16的一个byte数组,若是想转成string,可使用16进制字符集进行转码,代码代码以下ui
func main(){ sum:=sign.MD5.Encrypt([]byte(`红薯鸭`)) sumStr:=hex.EncodeToString(sum) }
OK,MD5到此结束,简单吧,下回我们聊聊AES...this