MariaDB ENCRYPT() Function
The MariaDB ENCRYPT() function is used to encrypt a string using UNIX crypt() and returns the encrypted value of the string. This function uses salt in the encryption process and the salt should be at least 2 character long. If the salt is not provided, this function will use a random value as salt. In special cases it returns the following:
- Returns NULL if salt is less than 2 characters in length.
- Returns NULL if the string is NULL.
- Returns NULL if UNIX crypt() is not available on the system.
Syntax
ENCRYPT(string, salt)
Parameters
string |
Required. Specify the plaintext string to be encrypted using UNIX crypt(). |
salt |
Optional. Specify the string should be at least 2 characters long. It is used in the encryption process. If it is not provided, this function will use a random value. |
Return Value
Returns the encrypted value of the string.
Example:
The example below shows the usage of ENCRYPT() function.
SELECT ENCRYPT('password'); Result: 'EY8ULaXsqebTI' SELECT ENCRYPT('password', 'key'); Result: 'keZqlq1fzdLxY' SELECT ENCRYPT('password', 'K'); Result: NULL SELECT ENCRYPT('alphacodingskills'); Result: 'dbtIyw3v.ciJY' SELECT ENCRYPT(NULL); Result: NULL
❮ MariaDB Functions