Skip to main content

Encryption and Masking Functions

Doris provides a set of built-in scalar functions for encryption, decryption, hash digest, and data masking, commonly used in SQL to protect sensitive fields such as phone numbers, ID numbers, and password digests. This page indexes these functions by category. For detailed syntax, parameters, and examples, refer to the corresponding SQL manual page for each function.

Applicable Scenarios

ScenarioRecommended Function
Symmetric encryption/decryption of sensitive fields (international algorithm)AES_ENCRYPT / AES_DECRYPT
Symmetric encryption/decryption of sensitive fields (Chinese national algorithm)SM4_ENCRYPT / SM4_DECRYPT
Generate irreversible hash digests (such as password storage or data verification)MD5, MD5SUM, SM3, SM3SUM, SHA, SHA2
Mask fields such as phone numbers and ID numbers in query outputDIGITAL_MASKING

Function Categories

All built-in encryption and masking functions are listed below, grouped by algorithm family.

Symmetric Encryption Functions

Used to perform reversible encryption and decryption on fields.

FunctionAlgorithm FamilyDescription
AES_ENCRYPTAES (international standard)AES encryption
AES_DECRYPTAES (international standard)AES decryption
SM4_ENCRYPTSM4 (Chinese national standard)SM4 encryption
SM4_DECRYPTSM4 (Chinese national standard)SM4 decryption

Hash Digest Functions

Used to generate fixed-length, irreversible digests, commonly used for password storage and data integrity verification.

FunctionAlgorithm FamilyDescription
MD5MD5Compute MD5 digest
MD5SUMMD5Compute MD5 checksum
SM3SM3 (Chinese national standard)Compute SM3 digest
SM3SUMSM3 (Chinese national standard)Compute SM3 checksum
SHASHACompute SHA digest
SHA2SHA-2Compute SHA-2 digest

Data Masking Functions

Used to display sensitive fields with masking in query output.

FunctionDescription
DIGITAL_MASKINGMask numeric strings such as phone numbers and bank card numbers