/
encrypt_sha1.go
58 lines (42 loc) · 1.07 KB
/
encrypt_sha1.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
50
51
52
53
54
55
56
57
58
package encrypt
import (
"crypto/sha1"
"github.com/jumper86/jumper_transform/interf"
"github.com/jumper86/jumper_transform/def"
"github.com/jumper86/jumper_transform/util"
)
type encryptOpSha1 struct {
}
func NewencryptOpSha1(params []interface{}) interf.EncryptOp {
var op encryptOpSha1
op.init(params)
return &op
}
func (self *encryptOpSha1) init(params []interface{}) bool {
return true
}
func (self *encryptOpSha1) Operate(direct int8, input interface{}, output interface{}) (bool, error) {
if direct == def.Forward {
tmpOutput, err := self.Encrypt(input.([]byte))
if err != nil {
return false, err
}
*(output.(*[]byte)) = tmpOutput
return true, nil
} else {
return false, def.ErrSha1NoDecrypt
}
return true, nil
}
func (*encryptOpSha1) Encrypt(data []byte) ([]byte, error) {
defer util.TraceLog("encryptOpSha1.Encrypt")()
s := sha1.New()
s.Write(data)
r := s.Sum(nil)
rst := r[:]
return rst, nil
}
func (*encryptOpSha1) Decrypt(data []byte) ([]byte, error) {
defer util.TraceLog("encryptOpSha1.Decrypt")()
return nil, def.ErrSha1NoDecrypt
}