MCPcopy Index your code
hub / github.com/apache/devlake / AesDecrypt

Function AesDecrypt

backend/core/plugin/plugin_utils.go:120–140  ·  view source on GitHub ↗

AesDecrypt AES decryption

(crypted, key []byte)

Source from the content-addressed store, hash-verified

118
119// AesDecrypt AES decryption
120func AesDecrypt(crypted, key []byte) ([]byte, errors.Error) {
121 // Uniformly use sha256 to process as 32-bit Byte (256-bit bit)
122 sha256Key := sha256.Sum256(key)
123 key = sha256Key[:]
124 block, err := aes.NewCipher(key)
125 if err != nil {
126 return nil, errors.Convert(err)
127 }
128 // Get the block size and check whether the ciphertext length is legal
129 blockSize := block.BlockSize()
130 if len(crypted)%blockSize != 0 {
131 return nil, errors.Default.New(fmt.Sprintf("The length of the data to be decrypted is [%d], so cannot match the required block size [%d]", len(crypted), blockSize))
132 }
133
134 // Decrypt and unalign data
135 blockMode := cipher.NewCBCDecrypter(block, key[:blockSize])
136 origData := make([]byte, len(crypted))
137 blockMode.CryptBlocks(origData, crypted)
138 origData = PKCS7UnPadding(origData)
139 return origData, nil
140}
141
142// RandomEncryptionSecret will return a random string of length 128
143func RandomEncryptionSecret() (string, errors.Error) {

Callers 1

DecryptFunction · 0.85

Calls 3

PKCS7UnPaddingFunction · 0.85
NewMethod · 0.65
ConvertMethod · 0.45

Tested by

no test coverage detected