forked from TykTechnologies/tyk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash.go
36 lines (26 loc) · 793 Bytes
/
hash.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
package signature_validator
import (
"crypto/md5"
"crypto/sha256"
"strconv"
)
type Hasher interface {
Name() string
Hash(token string, sharedSecret string, timeStamp int64) []byte
}
type MasherySha256Sum struct{}
func (m MasherySha256Sum) Name() string {
return "MasherySHA256"
}
func (m MasherySha256Sum) Hash(token string, sharedSecret string, timeStamp int64) []byte {
signature := sha256.Sum256([]byte(token + sharedSecret + strconv.FormatInt(timeStamp, 10)))
return signature[:]
}
type MasheryMd5sum struct{}
func (m MasheryMd5sum) Name() string {
return "MasheryMD5"
}
func (m MasheryMd5sum) Hash(token string, sharedSecret string, timeStamp int64) []byte {
signature := md5.Sum([]byte(token + sharedSecret + strconv.FormatInt(timeStamp, 10)))
return signature[:]
}