MySQL: ENCRYPT Function

  • Post author:
  • Post category:MySQL
  • Post comments:1 Comment
MySQL ENCRYPT Function

In this guide, we will explain 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 :

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

Example

Let’s look at some ENCRYPT function examples and explore how to use the ENCRYPT function.

For example:

mysql> SELECT ENCRYPT('abc');
Result: 'HodO.ryHDWKR2'

mysql> SELECT ENCRYPT('password');
Result: 'Xp7fKf8gFYoMc'

mysql> SELECT ENCRYPT('adglob');
Result: 'ipQqyRshr94pU'

mysql> SELECT ENCRYPT('adglob', '123');
Result: '120RNc3daWyrU'

mysql> SELECT ENCRYPT('adglob', '1');
Result: NULL

mysql> SELECT ENCRYPT(NULL);
Result: NULL

Next Topic : Click Here

This Post Has One Comment

Leave a Reply