MCPcopy Create free account
hub / github.com/LagrangeDev/LagrangeGo / AESGCMEncrypt

Function AESGCMEncrypt

utils/crypto/aes.go:9–30  ·  view source on GitHub ↗
(data []byte, key []byte)

Source from the content-addressed store, hash-verified

7)
8
9func AESGCMEncrypt(data []byte, key []byte) ([]byte, error) {
10 nonce := make([]byte, 12)
11 if _, err := rand.Read(nonce); err != nil {
12 return nil, err
13 }
14
15 block, err := aes.NewCipher(key)
16 if err != nil {
17 return nil, err
18 }
19 aead, err := cipher.NewGCM(block)
20 if err != nil {
21 return nil, err
22 }
23 ciphertext := aead.Seal(nil, nonce, data, nil)
24
25 result := make([]byte, len(nonce)+len(ciphertext))
26 copy(result[:len(nonce)], nonce)
27 copy(result[len(nonce):], ciphertext)
28
29 return result, nil
30}
31
32func AESGCMDecrypt(data []byte, key []byte) ([]byte, error) {
33 nonce := data[:12]

Callers 2

buildNtloginRequestFunction · 0.92
BuildKexExchangeRequestFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected