Name

DES_ENCRYPT( )

Synopsis

DES_ENCRYPT(string, [key])

This function returns encrypted text using the triple DES algorithm with a 128-bit key length. It returns NULL if an error occurs. This function will work only if MySQL has been configured for SSL support. To use this function, a key file must be created and specified with the --des-key-file option when starting the mysqld daemon. To encrypt a given string, either a key string must be given as the second argument of the function, or it can be retrieved from a file containing key strings.

A key file should be set up with a separate key string on each line. Each line should begin with a single-digit number (0-9) as an index, followed by a space before the key string (e.g., key_number des_string).

To reference key strings in the key file, the number of the line to retrieve may be given as the key to the function. If a key number is not given with this function, the first key in the key file is used for encryption.

The results of this function can be reversed with DES_DECRYPT( ). This function is available as of Version 4.0.1 of MySQL.

UPDATE orders
   SET credit_card_nbr = DES_ENCRYPT('4011-7839-1234-4321')
   WHERE order_nbr = '8347';

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.