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

MariaDB ENCRYPT SQL Function - Encrypt with Unix-crypt()

ENCRYPTSyntax:ENCRYPT(String [, Salt])
Return value:CHAR
Function type:Encryption & Compression
Function Description

The ENCRYPT() function encrypts the first 8 characters of a "String" using the Unix system call crypt() and returns an encrypted binary string.

The optional argument "Salt" should be at least two characters long, otherwise the function returns NULL.

If "Salt" is not specified, a random value is used depending on the time.

ENCRYPT() should not be used with utf16, utf32 or ucs2 multibyte character sets, since crypt() is a string with a null byte at the end expected.

"String" is truncated after 8 characters when encrypted.


If the have_crypt system variable is not enabled, the ENCRYPT() function always returns NULL.

On Windows, the function always returns NULL because UNIX feature crypt() does not exist and have_crypt cannot be enabled.


Numeric values ​​in the "String" and "Salt" arguments are interpreted as a character string.

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

If the value of the "String" or "Salt" argument is NULL, the ENCRYPT() function returns NULL.


This feature is not present in MySQL 8.0.

SQL Examples for the ENCRYPT function

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22

select encrypt('Test');
select encrypt('Test');
DO SLEEP(1);                      /* Waiting 1 second */
select encrypt('Test');

select encrypt('Test''Salt');
select encrypt('Test''Salt');
DO SLEEP(1);                      /* Waiting 1 second */
select encrypt('Test''Salt');

select encrypt(123456, '789');
select encrypt(123456, 789);

select encrypt('TestTest''Salt');
select encrypt('TestTestTest''Salt');

select encrypt('''Salt');
select encrypt('Test''S');
select encrypt(null'Salt');
select encrypt('Test'null);

encrypt('Test')
varchar(13) BINARY
7IGXksZ4Yqlzg
encrypt('Test')
varchar(13) BINARY
7IGXksZ4Yqlzg
encrypt('Test')
varchar(13) BINARY
8IfmSV7R/QO1g
encrypt('Test', 'Salt')
varchar(13) BINARY
Sa9IoEm4G2IBE
encrypt('Test', 'Salt')
varchar(13) BINARY
Sa9IoEm4G2IBE
encrypt('Test', 'Salt')
varchar(13) BINARY
Sa9IoEm4G2IBE
encrypt(123456, '789')
varchar(13) BINARY
781oWEAeAowtk
encrypt(123456, 789)
varchar(13) BINARY
781oWEAeAowtk
encrypt('TestTest', 'Salt')
varchar(13) BINARY
Saej54y9rHXdo
encrypt('TestTestTest', 'Salt')
varchar(13) BINARY
Saej54y9rHXdo
encrypt('', 'Salt')
varchar(13) BINARY
 
encrypt('Test', 'S')
varchar(13) BINARY
NULL
encrypt(null, 'Salt')
varchar(13) BINARY
NULL
encrypt('Test', null)
varchar(13) BINARY
NULL
The examples were created with the MyWAY SQL manager: Download

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

In MariaDB the ENCRYPT() function is used to encrypt a string using the Unix encryption library. It should be noted that the ENCRYPT() function uses a platform-dependent one-way hash function instead of an encryption algorithm and is not suitable for reversible encryption. The function returns a character string as a result.

The algorithm used may vary or may not exist depending on the operating system used and the version of the database server. The function can be used for password hashing and user password verification. To check if a given string matches an encrypted hash, the ENCRYPT() function can be used in a comparison expression.
DES_ENCRYPTELTENCODEENCRYPTEXPEXPORT_SETEXTRACT

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

DES_ENCRYPTDES_ENCRYPT(String [, Key])
More about DES_ENCRYPT Function

ENCODEENCODE(String, Password)
More about ENCODE 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 ENCRYPT SQL function: mariadb.com
Updated: 2023-09-17ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer