MCPcopy Index your code
hub / github.com/rilldata/rill / encrypt

Function encrypt

admin/database/postgres/postgres.go:4030–4049  ·  view source on GitHub ↗

encrypts plaintext using AES-GCM with the given key and returns the base64 encoded ciphertext

(plaintext, key []byte)

Source from the content-addressed store, hash-verified

4028
4029// encrypts plaintext using AES-GCM with the given key and returns the base64 encoded ciphertext
4030func encrypt(plaintext, key []byte) ([]byte, error) {
4031 block, err := aes.NewCipher(key)
4032 if err != nil {
4033 return nil, err
4034 }
4035
4036 aesGCM, err := cipher.NewGCM(block)
4037 if err != nil {
4038 return nil, err
4039 }
4040
4041 nonce := make([]byte, aesGCM.NonceSize())
4042 if _, err := io.ReadFull(rand.Reader, nonce); err != nil {
4043 return nil, err
4044 }
4045
4046 // nonce is prepended to the ciphertext, so it can be used for decryption
4047 ciphertext := aesGCM.Seal(nonce, nonce, plaintext, nil)
4048 return ciphertext, nil
4049}
4050
4051// decrypts the ciphertext using AES-GCM with the given key and returns the plaintext
4052func decrypt(ciphertext, key []byte) ([]byte, error) {

Callers 1

encryptMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected