Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

MySQL | DES_ENCRYPT ( ) Function

  • Last Updated : 13 Nov, 2019

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.


DES_ENCRYPT(plaintext_string, [key_number | key_string]);

Parameters Used:

  • plaintext_string – It is used to specify a string which is to be encrypted.
  • key_number – It is used to specify a number in the range of 0 to 9 from the DES key file.
  • key_string – It is used to specify a string which is used for encrypting the plain-text string.

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

Supported Versions of MySQL:

  • MySQL 5.7
  • MySQL 5.6
  • MySQL 5.5
  • MySQL 5.1
  • MySQL 5.0
  • MySQL 4.1

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

DES_ENCRYPT('geeksforgeeks', 5); 



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

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


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

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



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!