Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Wednesday 20 March 2024

ENCRYPT function in MySQL

MySQL ENCRYPT function is used to encrypt a string using UNIX crypt().


Syntax:-


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.


The ENCRYPT function is supported in following versions of MySQL:


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

Let's look at the example:-

Let's look at some MySQL ENCRYPT function examples and explore how to use the ENCRYPT function in MySQL.


SELECT ENCRYPT('CHANCHAL');

Result: 'PodOryDRWKR2'


SELECT ENCRYPT('WANKHADE');

Result: 'CPp7fKf8gFYoMc'


SELECT ENCRYPT('CHANCHALWANKHADE', '123');

Result: '10QRN2c3daYyrU'


SELECT ENCRYPT('CHANCHALWANKHADE', '1');

Result: NULL


SELECT ENCRYPT(NULL);

Result: NULL

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.