Syntax
DES_ENCRYPT(str[,{key_num|key_str}])
Purpose
This function is available only when OceanBase Database supports SSL.
The key_str argument specifies the key for encrypting the str string. If you do not specify this argument, the first key in the DES key file is used. The value of key_num is the key ID in the DES key file, which ranges from 0 to 9.
This function returns a binary string. The first character in the string is CHAR(128 | key_num). If an error occurs, this function returns NULL. key_num is set to 128 to make it easier to identify the encryption key. If a string key is used, key_num is 127.
The string length in the result is calculated based on the following formula:
new_len = orig_len + (8 - (orig_len % 8)) + 1
Each line in the DES key file is in key_num des_key_str_ format. Each key_num value must be a digit ranging from 0 to 9. Lines in the file can be arranged in any order. des_key_str specifies the string for encrypting information. A number and a key must be separated with at least one space. If you do not specify any key argument for this function, the first key is used by default.
Note
You cannot use the --des_key_file command to edit the DES key file in OceanBase Database. Therefore, the keys read by DES_ENCRYPT() and DES_DECRYPT() from the key file are the same as those in the default key file of MySQL 8.0.
Examples
obclient [test]> SELECT DES_ENCRYPT('text', CONCAT('ob_random_salt','ob_secret_password'));
+--------------------------------------------------------------------+
| DES_ENCRYPT('text', CONCAT('ob_random_salt','ob_secret_password')) |
+--------------------------------------------------------------------+
| ]UA |
+--------------------------------------------------------------------+
1 row in set