Skip to content

encrypt

encrypt replaces each detected entity with an AES-SIV ciphertext. The output is reversible: a user or service with the same key can decrypt a ciphertext back to the original value.

The same plaintext encrypted with the same key produces the same ciphertext every time. This makes encrypted values stable across calls when the key and operator configuration match. Use that stability when you need to:

  • Join two tables on encrypted columns without placing plaintext in the de-identified output.
  • Compare a new value against previously-encrypted records.
  • Re-identify a row later with the key.

The trade-off: deterministic ciphertexts are linkable, and anyone with the key can decrypt them. Treat both the key and the encrypted values as sensitive.

ParameterTypeDefaultDescription
keySTRING— (required)The encryption key. Keep this key secret — anyone with the key can decrypt.
entity_collapseBOOLEANfalseOperator-level opt-in for identity collapse. When request-level entity_collapse is enabled, aliases in the same collapsed group share one ciphertext.
SELECT app_public.mask(
'Email: sarah.chen@gmail.com',
OBJECT_CONSTRUCT(
'entity_config', OBJECT_CONSTRUCT(
'EMAIL_ADDRESS', OBJECT_CONSTRUCT(
'operator', 'encrypt',
'operator_params', OBJECT_CONSTRUCT('key', '<secret-key>')
)
)
)
);
-- Email: Q2lwaGVydGV4dEJhc2U2NEVuY29kZWRIZXJl...

Ciphertext is emitted as base64. Pass it to app_public.decrypt (below), with the same key, to recover the original value.

Example — collapse aliases before encrypting

Section titled “Example — collapse aliases before encrypting”

By default, encrypt is deterministic for the detected entity value after standard normalization. To treat aliases such as "Sarah Chen", "Chen", and "Dr. Chen" as the same person before encryption, enable request-level entity_collapse and set operator_params.entity_collapse to TRUE:

OBJECT_CONSTRUCT(
'entity_collapse', 0.5,
'entity_config', OBJECT_CONSTRUCT(
'PERSON', OBJECT_CONSTRUCT(
'operator', 'encrypt',
'operator_params', OBJECT_CONSTRUCT(
'key', '<secret-key>',
'entity_collapse', TRUE
)
)
)
)
  • Authorized re-identification workflows: replace PII for one audience while allowing a privileged workflow to decrypt values when policy permits.
  • Break-glass access: keep reversible values in a controlled dataset while restricting key access to a small set of roles.
  • Controlled matching: join or compare records on encrypted identifiers without showing the original identifier in the de-identified output.
  • Review workflows: provide reversible encrypted values only when the reviewer is authorized to hold or use the key.
  • Key management is critical. Use a Snowflake secret or a secure configuration store. Do not hardcode keys in SQL files, shared worksheets, query text, or application logs.
  • encrypt produces reversible, linkable values. It does not make data anonymous.
  • Anyone holding the key can decrypt. Anyone with access to both the key and the ciphertext can re-identify the original value.
  • If operator_params.entity_collapse=true, aliases in a collapsed group encrypt from the same collapse result and therefore share one ciphertext.
  • Use the same key only across datasets that intentionally need joinability. Rotate and scope keys according to your organization’s policies.
  • Use hash, faker, type_numbered, or constant when consumers should not have a reversible path to the original values.
  • Deterministic encryption can reveal that two records contain the same underlying value when the same key and operator settings are used.
  • Losing the key means Agent Mask cannot recover the original values from the ciphertext.

Reverse encryption with app_public.decrypt(ciphertext, key):

SELECT app_public.decrypt(
'Q2lwaGVydGV4dEJhc2U2NEVuY29kZWRIZXJl...',
'<secret-key>'
);
-- 'sarah.chen@gmail.com'

app_public.decrypt is granted to the app_admin role only. Re-identification is treated as a privileged operation; consumers who only need to mask data use app_user.

A wrong key or tampered ciphertext raises an error. AES-SIV authenticates the ciphertext, so decryption does not silently return a different value.

If you need to decrypt outside Snowflake, use a compatible AES-SIV implementation with the same key and base64 ciphertext format. Anyone with the key can decrypt outside Agent Mask; the SQL function is a convenience for Snowflake workflows.

  • hash — deterministic but not reversible.
  • faker — synthetic but not mappable back.