MCPcopy
hub / github.com/apache/devlake / AesEncrypt

Function AesEncrypt

backend/core/plugin/plugin_utils.go:102–117  ·  view source on GitHub ↗

AesEncrypt AES encryption, CBC

(origData, key []byte)

Source from the content-addressed store, hash-verified

100
101// AesEncrypt AES encryption, CBC
102func AesEncrypt(origData, key []byte) ([]byte, errors.Error) {
103 // data alignment fill and encryption
104 sha256Key := sha256.Sum256(key)
105 key = sha256Key[:]
106 block, err := aes.NewCipher(key)
107 if err != nil {
108 return nil, errors.Convert(err)
109 }
110 // data alignment fill and encryption
111 blockSize := block.BlockSize()
112 origData = PKCS7Padding(origData, blockSize)
113 blockMode := cipher.NewCBCEncrypter(block, key[:blockSize])
114 crypted := make([]byte, len(origData))
115 blockMode.CryptBlocks(crypted, origData)
116 return crypted, nil
117}
118
119// AesDecrypt AES decryption
120func AesDecrypt(crypted, key []byte) ([]byte, errors.Error) {

Callers 1

EncryptFunction · 0.85

Calls 2

PKCS7PaddingFunction · 0.85
ConvertMethod · 0.45

Tested by

no test coverage detected