MCPcopy Create free account
hub / github.com/TryGOTry/C2_Demo / AESEncrypt

Function AESEncrypt

C2_Client_Go/encode/encode.go:10–26  ·  view source on GitHub ↗

AEs加密

(src []byte, key []byte)

Source from the content-addressed store, hash-verified

8
9
10func AESEncrypt(src []byte, key []byte) (encrypted []byte) {
11 cipher, _ := aes.NewCipher(generateKey(key))
12 length := (len(src) + aes.BlockSize) / aes.BlockSize
13 plain := make([]byte, length*aes.BlockSize)
14 copy(plain, src)
15 pad := byte(len(plain) - len(src))
16 for i := len(src); i < len(plain); i++ {
17 plain[i] = pad
18 }
19 encrypted = make([]byte, len(plain))
20 // 分组分块加密
21 for bs, be := 0, cipher.BlockSize(); bs <= len(src); bs, be = bs+cipher.BlockSize(), be+cipher.BlockSize() {
22 cipher.Encrypt(encrypted[bs:be], plain[bs:be])
23 }
24
25 return encrypted
26}
27
28func AESDecrypt(encrypted []byte, key []byte) (decrypted []byte) {
29 cipher, _ := aes.NewCipher(generateKey(key))

Callers 1

EncodestrFunction · 0.70

Calls 1

generateKeyFunction · 0.70

Tested by

no test coverage detected