-
Notifications
You must be signed in to change notification settings - Fork 0
/
aes_std.go
40 lines (34 loc) · 919 Bytes
/
aes_std.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
package anenc
import (
"errors"
)
// This is a standard one; so the user don't have to create object if they don't want to.
var std_aes = NewAES(nil)
func Encrypt(passwd, data []byte) ([]byte, error) {
if len(passwd) == 0 || len(data) == 0 {
return nil, errors.New("either passwd or data missing")
}
std_aes.SetPasswd(passwd)
return std_aes.Encrypt(data)
}
func Decrypt(passwd, encryptedData []byte) ([]byte, error) {
if len(passwd) == 0 || len(encryptedData) == 0 {
return nil, errors.New("either passwd or data missing")
}
std_aes.SetPasswd(passwd)
return std_aes.Decrypt(encryptedData)
}
func MustEncrypt(passwd, data, fallback []byte) []byte {
if out, err := Encrypt(passwd, data); err != nil {
return fallback
} else {
return out
}
}
func MustDecrypt(passwd, data, fallback []byte) []byte {
if out, err := Decrypt(passwd, data); err != nil {
return fallback
} else {
return out
}
}