Open In App

MySQL | DES_ENCRYPT ( ) Function

The MySQL DES_ENCRYPT function is used for encrypting a string using DES(Data Encryption Standard) algorithm. The MySQL DES_ENCRYPT function uses a key to encrypt a string.

The value returned by the DES_ENCRYPT function is an encrypted string or NULL. The DES_ENCRYPT function accepts three parameters which are the plain text string and a key string and a key number to encrypt the string.



Syntax:

DES_ENCRYPT(plaintext_string, [key_number | key_string]);

Parameters Used:



Return Value:
The DES_ENCRYPT function in MySQL returns an encrypted string.

Supported Versions of MySQL:

Example-1: Implementing DES_ENCRYPT function on a string by only passing the key number argument.

SELECT 
DES_ENCRYPT('geeksforgeeks', 5); 

Output:

??p4???c????-? 

Example-2: Implementing DES_ENCRYPT function on a string by passing both the key number and the key string arguments.

SELECT 
DES_ENCRYPT('geeksforgeeks', 7), 
DES_ENCRYPT('geeksforgeeks', 'TestPassward'); 

Output:

??p4???c????-?    ??]?? ???{?}\\?t? 

Example-3: Implementing DES_ENCRYPT function on a NULL string.

SELECT 
DES_ENCRYPT(NULL, 7); 

Output:

NULL 
Article Tags :
SQL