-
Notifications
You must be signed in to change notification settings - Fork 2
/
digest.go
49 lines (40 loc) · 845 Bytes
/
digest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package crypto4go
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"encoding/hex"
)
func MD5(value []byte) []byte {
var m = md5.New()
m.Write(value)
return m.Sum(nil)
}
func MD5String(value string) string {
return hex.EncodeToString(MD5([]byte(value)))
}
func SHA1(value []byte) []byte {
var s = sha1.New()
s.Write(value)
return s.Sum(nil)
}
func SHA1String(value string) string {
return hex.EncodeToString(SHA1([]byte(value)))
}
func SHA256(value []byte) []byte {
var s = sha256.New()
s.Write(value)
return s.Sum(nil)
}
func SHA256String(value string) string {
return hex.EncodeToString(SHA256([]byte(value)))
}
func SHA512(value []byte) []byte {
var s = sha512.New()
s.Write(value)
return s.Sum(nil)
}
func SHA512String(value string) string {
return hex.EncodeToString(SHA512([]byte(value)))
}