-
Notifications
You must be signed in to change notification settings - Fork 3
/
ecbPKCS5Padding.go
36 lines (31 loc) · 1.13 KB
/
ecbPKCS5Padding.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 aesKit
import (
"github.com/richelieu-yang/chimera/v3/src/crypto/base64Kit"
"github.com/zeromicro/go-zero/core/codec"
)
// EncryptEcbPKCS5PaddingToString 明文([]byte) => 密文(base64 string)
/*
@param key 密钥(must be 16/24/32 bit length)
*/
func EncryptEcbPKCS5PaddingToString(key []byte, plainData []byte) (string, error) {
cipherData, err := EncryptEcbPKCS5Padding(key, plainData)
if err != nil {
return "", err
}
return base64Kit.EncodeToString(cipherData), nil
}
// DecryptEcbPKCS5PaddingFromString 密文(base64 string) => 明文([]byte)
/*
@param key 密钥(must be 16/24/32 bit length)
*/
func DecryptEcbPKCS5PaddingFromString(key []byte, cipherText string) ([]byte, error) {
cipherData, err := base64Kit.DecodeString(cipherText)
if err != nil {
return nil, err
}
return DecryptEcbPKCS5Padding(key, cipherData)
}
// EncryptEcbPKCS5Padding 明文([]byte) => 密文([]byte)
var EncryptEcbPKCS5Padding func(key, plainText []byte) ([]byte, error) = codec.EcbEncrypt
// DecryptEcbPKCS5Padding 密文([]byte) => 明文([]byte)
var DecryptEcbPKCS5Padding func(key, cipherData []byte) ([]byte, error) = codec.EcbDecrypt