MySQL's own encryption and compression functions

1. About the PASSWORD function

Description:

The PASSWORD(str) function is used to modify the MySQL user password. For applications and WEB programs, it is recommended to use the MD5() function.

This function was removed after MySQL 8.x, and MySQL versions prior to 5.7.x are also distinguished. The old version generates 16-bit ciphertext and the new version has 41-bit.

The PASSWORD() function encryption is irreversible. If you need to compare the encrypted content in the database, you can only compare the encrypted content;

Specific examples are as follows:

mysql> SELECT PASSWORD("123456");

+-------------------------------------------+
| PASSWORD("123456")                        |
+-------------------------------------------+
| *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-------------------------------------------+

mysql> select LENGTH(PASSWORD("123456"));
+----------------------------+
| LENGTH(PASSWORD("123456")) |
+----------------------------+
|                         41 |
+----------------------------+

mysql> SELECT IF(PASSWORD("123456") = "*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9", true, false) isEqual;
+---------+
| isEqual |
+---------+
|       1 |
+---------+

2. Encryption and compression function

Detailed instructions on the official website: https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html#function_password

name description

AES_DECRYPT()

Use AES encryption
AES_ENCRYPT() Decrypt using AES
COMPRESS() Return the result as a binary string
MD5 () Calculate MD5 checksum
RANDOM_BYTES() Returns a random byte vector
SHA1(), SHA() Calculate the SHA-1 160-bit checksum
SHA2 () Calculate the SHA-2 checksum
STATEMENT_DIGEST() Calculate the statement digest hash value
STATEMENT_DIGEST_TEXT() Calculate the normalized sentence summary
UNCOMPRESS() Decompress string compression
UNCOMPRESSED_LENGTH() Returns the length of the string before compression
VALIDATE_PASSWORD_STRENGTH() Determine password strength

Many encryption and compression functions return strings, and their results may contain arbitrary byte values. If you want to store these results, use a column with a VARBINARY or BLOB binary string data type. This avoids the data value that will change after space removal or character set conversion, for example, if you use a non-binary string data type, it may appear (potential problems CHAR, VARCHAR, TEXT).

 

Guess you like

Origin blog.csdn.net/qq_41057885/article/details/109281451