MySQL: ENCRYPT Function
This MySQL tutorial explains how to use the MySQL ENCRYPT function with syntax and examples.
Description
The MySQL ENCRYPT function is used to encrypt a string using UNIX crypt().
Syntax
The syntax for the ENCRYPT function in MySQL is:
ENCRYPT( string [, salt ] )
Parameters or Arguments
- string
- The plaintext string that is encrypted using UNIX crypt().
- salt
- Optional. The string that is at least 2 characters long that is used in the encryption process. If salt is not provided, the ENCRYPT function will use a random value.
Note
- The ENCRYPT function will return NULL, if salt is less than 2 characters in length.
- The ENCRYPT function will return NULL, if the string is NULL.
- The ENCRYPT function will return NULL, if UNIX crypt() is not available on your system.
Applies To
The ENCRYPT function can be used in the following versions of MySQL:
- MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1
Example
Let's look at some MySQL ENCRYPT function examples and explore how to use the ENCRYPT function in MySQL.
For example:
mysql> SELECT ENCRYPT('abc'); Result: 'HodO.ryHDWKR2' mysql> SELECT ENCRYPT('password'); Result: 'Xp7fKf8gFYoMc' mysql> SELECT ENCRYPT('techonthenet'); Result: 'ipQqyRshr94pU' mysql> SELECT ENCRYPT('techonthenet', '123'); Result: '120RNc3daWyrU' mysql> SELECT ENCRYPT('techonthenet', '1'); Result: NULL mysql> SELECT ENCRYPT(NULL); Result: NULL
Advertisements