先从个简单点的,也是用的比较多MD5加密开始,不多说直接上代码
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进制字符集进行转码,代码代码如下
func main(){
sum:=sign.MD5.Encrypt([]byte(`红薯鸭`))
sumStr:=hex.EncodeToString(sum)
}
OK,MD5到此结束,简单吧,下回咱们聊聊AES...