MCPcopy Create free account
hub / github.com/devspace-sh/devspace / DecryptAES

Function DecryptAES

pkg/util/encryption/util.go:68–94  ·  view source on GitHub ↗

DecryptAES decrypts the given data with the given key

(key, data []byte)

Source from the content-addressed store, hash-verified

66
67// DecryptAES decrypts the given data with the given key
68func DecryptAES(key, data []byte) ([]byte, error) {
69 // Ensure key is 32 bytes long
70 key = PadKey(key)
71
72 c, err := aes.NewCipher(key)
73 if err != nil {
74 return nil, err
75 }
76
77 gcm, err := cipher.NewGCM(c)
78 if err != nil {
79 return nil, err
80 }
81
82 nonceSize := gcm.NonceSize()
83 if len(data) < nonceSize {
84 return nil, errors.Errorf("Data size is smaller than nonce size: %d < %d", len(data), nonceSize)
85 }
86
87 nonce, ciphertext := data[:nonceSize], data[nonceSize:]
88 plaintext, err := gcm.Open(nil, nonce, ciphertext, nil)
89 if err != nil {
90 return nil, err
91 }
92
93 return plaintext, nil
94}

Callers 3

LoadMethod · 0.92
NewCacheFromSecretFunction · 0.92
TestEncryptDecryptAESFunction · 0.85

Calls 2

PadKeyFunction · 0.85
ErrorfMethod · 0.45

Tested by 1

TestEncryptDecryptAESFunction · 0.68