MCPcopy
hub / github.com/pocketbase/pocketbase / Encrypt

Function Encrypt

tools/security/encrypt.go:14–37  ·  view source on GitHub ↗

Encrypt encrypts "data" with the specified "key" (must be valid 32 char AES key). This method uses AES-256-GCM block cypher mode.

(data []byte, key string)

Source from the content-addressed store, hash-verified

12//
13// This method uses AES-256-GCM block cypher mode.
14func Encrypt(data []byte, key string) (string, error) {
15 block, err := aes.NewCipher([]byte(key))
16 if err != nil {
17 return "", err
18 }
19
20 gcm, err := cipher.NewGCM(block)
21 if err != nil {
22 return "", err
23 }
24
25 nonce := make([]byte, gcm.NonceSize())
26
27 // populates the nonce with a cryptographically secure random sequence
28 if _, err := io.ReadFull(crand.Reader, nonce); err != nil {
29 return "", err
30 }
31
32 cipherByte := gcm.Seal(nonce, nonce, data, nil)
33
34 result := base64.StdEncoding.EncodeToString(cipherByte)
35
36 return result, nil
37}
38
39// Decrypt decrypts encrypted text with key (must be valid 32 chars AES key).
40//

Callers 2

TestEncryptFunction · 0.92
DBExportMethod · 0.92

Calls

no outgoing calls

Tested by 1

TestEncryptFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…