©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

MariaDB DES_ENCRYPT SQL Function - Encrypt with Triple-DES-Algorithmus

DES_ENCRYPTSyntax:DES_ENCRYPT(String [, Key])
Return value:BINARY
Function type:Encryption & Compression
Function Description

The DES_ENCRYPT() function encrypts the "String" with the specified "Key" using the Triple-DES algorithm.

Without a "Key" argument, the first key from the DES key file is used: key number 0.

For a "Key" with a numeric argument, the specified key number (0-9) from the DES key file is used.

With a "Key" with string argument, the specified string is used to encrypt "String".

The return is a binary string where the first character is CHAR(128+Key-no) or CHAR(255).

If a character string is used as "Key", the first character is CHAR(255) (0xFF), otherwise CHAR(128+Key-no)< /b> (0x80).

If a numeric value is specified as the "Key", it must be between 0 and 9, otherwise the function returns NULL.

If an error occurs, the DES_ENCRYPT() function returns NULL.


Numeric values ​​in the "String" argument are interpreted as a character string.

If "String" contains no characters, an empty string is returned.

If the value of the "String" argument is NULL, the DES_ENCRYPT() function returns NULL.


The key file can be specified with the --des-key-file server option.

This feature only works if MariaDB has been configured with TLS support.

As of MariaDB 10.10, this feature is deprecated and will be removed in future releases.

This feature is not present in MySQL 8.0.


The DES_DECRYPT() function can be used for decryption.

SQL Examples for the DES_ENCRYPT function

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16

select hex(des_encrypt('Test'));
select hex(des_encrypt('Test''Key'));
select hex(des_encrypt('Test', 0));
select hex(des_encrypt('Test', 9));

select hex(des_encrypt(123456));
select hex(des_encrypt(123456, 'Key'));
select hex(des_encrypt(123456, 0));
select hex(des_encrypt(123456, 9));

select des_encrypt('''Key');

select hex(des_encrypt('Test', 90));
select hex(des_encrypt(null, 9));

hex(des_encrypt('Test'))
varchar(26) BINARY
80EA0A9DB4CC10869F
hex(des_encrypt('Test', 'Key'))
varchar(26) BINARY
FFA0ABBB0826A039EE
hex(des_encrypt('Test', 0))
varchar(26) BINARY
80EA0A9DB4CC10869F
hex(des_encrypt('Test', 9))
varchar(26) BINARY
89EA0A9DB4CC10869F
hex(des_encrypt(123456))
varchar(30) BINARY
80AE77A7D188B8CB6F
hex(des_encrypt(123456, 'Key'))
varchar(30) BINARY
FFFFAE19DABE7DFBF6
hex(des_encrypt(123456, 0))
varchar(30) BINARY
80AE77A7D188B8CB6F
hex(des_encrypt(123456, 9))
varchar(30) BINARY
89AE77A7D188B8CB6F
des_encrypt('', 'Key')
varchar(9) BINARY
 
hex(des_encrypt('Test', 90))
varchar(26) BINARY
NULL
hex(des_encrypt(null, 9))
varchar(18) BINARY
NULL
The examples were created with the MyWAY SQL manager: Download

How to use the DES_ENCRYPT() function in MySQL and MariaDB databases

The DES_ENCRYPT() function in MariaDB is used to encode a string using the DES (Data Encryption Standard) algorithm to encrypt. The function takes as arguments the string to be encrypted and the encryption key and returns the encrypted value as a binary string. DES is an older encryption algorithm and is considered less secure compared to more modern algorithms like AES, so using AES encryption is recommended instead.
DEFAULTDEGREESDES_DECRYPTDES_ENCRYPTELTENCODEENCRYPT

Further MySQL und MariaDB SQL Encryption & Compression

AES_DECRYPTAES_DECRYPT(String, Key)
More about AES_DECRYPT Function

AES_ENCRYPTAES_ENCRYPT(String, Key)
More about AES_ENCRYPT Function

COMPRESSCOMPRESS(String)
More about COMPRESS Function

DECODEDECODE(Binary string, Password)
More about DECODE Function

DES_DECRYPTDES_DECRYPT(Binary string [, Key])
More about DES_DECRYPT Function

ENCODEENCODE(String, Password)
More about ENCODE Function

ENCRYPTENCRYPT(String [, Salt])
More about ENCRYPT Function

FROM_BASE64FROM_BASE64(String)
More about FROM_BASE64 Function

MD5MD5(String)
More about MD5 Function

OLD_PASSWORDOLD_PASSWORD(String)
More about OLD_PASSWORD Function

PASSWORDPASSWORD(String)
More about PASSWORD Function

RANDOM_BYTESRANDOM_BYTES(Length)
More about RANDOM_BYTES Function

SHASHA(String)
More about SHA Function

SHA1SHA1(String)
More about SHA1 Function

SHA2SHA2(String, Length)
More about SHA2 Function

TO_BASE64TO_BASE64(String)
More about TO_BASE64 Function

UNCOMPRESSUNCOMPRESS(Binary string)
More about UNCOMPRESS Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the DES_ENCRYPT SQL function: mariadb.com
Updated: 2023-09-17ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer