-
Notifications
You must be signed in to change notification settings - Fork 4
/
crypto.go
42 lines (37 loc) · 923 Bytes
/
crypto.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
// Copyright 2018 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Blue Oak Model License
// license that can be found in the LICENSE file.
package funcmap
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"encoding/hex"
)
// MD5 returns the sha checksum of s.
func MD5(s interface{}) (string, error) {
ss, err := toStringE(s)
if err != nil {
return "", err
}
hash := md5.Sum([]byte(ss))
return hex.EncodeToString(hash[:]), nil
}
// SHA1 returns the sha checksum of s.
func SHA1(s interface{}) (string, error) {
ss, err := toStringE(s)
if err != nil {
return "", err
}
hash := sha1.Sum([]byte(ss))
return hex.EncodeToString(hash[:]), nil
}
// SHA256 returns the sha checksum of s.
func SHA256(s interface{}) (string, error) {
ss, err := toStringE(s)
if err != nil {
return "", err
}
hash := sha256.Sum256([]byte(ss))
return hex.EncodeToString(hash[:]), nil
}