Hash加密之sha256
飞儿506
发表于 2022-11-12 16:14:02
132
0
0
sha256字符加密3 \; R! ?* z( R
func Sha256v2()[]byte{6 S3 V) O: i( m% o8 Z/ n0 q2 w
//初始化一个sha256对象$ o) c$ l; M/ b
h := sha256.New()
//将内容写入对象
h.Write([]byte("hello world\n"))
//对对象中的内容进行校检计算% ]7 b9 T) q1 y0 l0 ]' E9 ]
return h.Sum(nil)- [6 P# D% r7 L% E
}; P+ X6 N7 b0 Z4 ?) P6 |" `' B! ^
sha256文件加密8 d5 R' w( Y8 O: Q
//golang打开文件的两种方式: Y0 X/ ?0 o; t8 \, S" o
//f, err := os.Open("abc.txt")
f, err := os.OpenFile("abc.txt", os.O_RDONLY, 0777)7 f$ x' {& w* V* a, V
if err != nil {
fmt.Println(err)
}
defer f.Close()
h := sha256.New()
//从src(f)中复制数据到des(h)
if _, err := io.Copy(h, f); err != nil {
fmt.Println(err)
}
return h.Sum(nil)
成为第一个吐槽的人