-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaes_encrypt_opts.go
99 lines (81 loc) · 1.9 KB
/
aes_encrypt_opts.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package criptus
type AESOptions func(*AESParams) error
type AESParams struct {
specialSign string
key string // Key, it is recommended to use a 5-8 digit key
iv string // Initial Vector 16 bytes
aesModeType AesModeType
aesKeyType AesKeyType
aesKey []byte
PlainTextLength int
}
func newAESParams(opts ...AESOptions) (*AESParams, error) {
options := &AESParams{}
for _, opt := range opts {
err := opt(options)
if err != nil {
return &AESParams{}, err
}
}
return options, nil
}
func AESWithSpecialSign(specialSign string) AESOptions {
return func(params *AESParams) error {
params.specialSign = specialSign
return nil
}
}
func AESWithKey(key string) AESOptions {
return func(params *AESParams) error {
params.key = key
return nil
}
}
func AESWithIV(iv string) AESOptions {
return func(params *AESParams) error {
params.iv = iv
return nil
}
}
func AESWithAesModeType(aesModeType AesModeType) AESOptions {
return func(params *AESParams) error {
params.aesModeType = aesModeType
return nil
}
}
func AESWithAesKeyType(aesKeyType AesKeyType) AESOptions {
return func(params *AESParams) error {
params.aesKeyType = aesKeyType
return nil
}
}
func (p AESParams) GetSpecialSign() string {
return p.specialSign
}
func (p AESParams) GetKey() string {
return p.key
}
func (p AESParams) GetIV() string {
return p.iv
}
func (p AESParams) GetAesModeType() AesModeType {
return p.aesModeType
}
func (p AESParams) GetAesKeyType() AesKeyType {
return p.aesKeyType
}
func (p AESParams) SetSpecialSign(specialSign string) {
p.specialSign = specialSign
}
func (p *AESParams) SetKey(key string) {
p.key = key
}
func (p *AESParams) SetIV(iv string) {
p.iv = iv
}
func (p *AESParams) SetAesModeType(aesModeType AesModeType) {
p.aesModeType = aesModeType
}
func (p *AESParams) SetAesKeyType(aesKeyType AesKeyType) {
p.aesKeyType = aesKeyType
}