-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathjasypt.go
46 lines (39 loc) · 1.16 KB
/
jasypt.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
package jasypt
import (
"github.com/Mystery00/go-jasypt/encryption"
"github.com/Mystery00/go-jasypt/iv"
"github.com/Mystery00/go-jasypt/salt"
)
func New(algorithm string, config encryption.EncryptorConfig) encryption.Encryptor {
switch algorithm {
case "PBEWithHMACSHA512AndAES_256":
return encryption.NewPBEWithHMACSHA512AndAES_256(config)
case "PBEWithMD5AndDES":
return encryption.NewPBEWithMD5AndDES(config)
default:
panic(`unknown algorithm`)
}
}
type Config func(*encryption.EncryptorConfig)
func NewConfig(configList ...Config) encryption.EncryptorConfig {
encryptorConfig := encryption.EncryptorConfig{}
for _, c := range configList {
c(&encryptorConfig)
}
return encryptorConfig
}
func SetPassword(password string) Config {
return func(encryptorConfig *encryption.EncryptorConfig) {
encryptorConfig.Password = password
}
}
func SetSaltGenerator(generator salt.Generator) Config {
return func(encryptorConfig *encryption.EncryptorConfig) {
encryptorConfig.SaltGenerator = generator
}
}
func SetIvGenerator(generator iv.Generator) Config {
return func(encryptorConfig *encryption.EncryptorConfig) {
encryptorConfig.IvGenerator = generator
}
}