MySQL encryption and decryption examples

MySQL encryption and decryption examples

MySQL encryption and decryption examples

Data encryption and decryption are very important in the security field. For programmers, storing user passwords in ciphertext in the database is of great significance to intruders who steal user privacy.
There are a variety of front-end encryption algorithms that can be used for data encryption and decryption. Here I recommend a simple database-level data encryption and decryption solution. Taking the MySQL database as an example, it has built-in corresponding encryption functions (AES_ENCRYPT()) and decryption functions (AES_DECRYPT()).

When building a table, pay attention to the type of field. As shown in the following figure:

Insert encrypted data into the table

The above insert statement has three fields, "Username", "Password" and "Encrypted Password". The AES_ENCRYPT() function requires a "key" to assist with encryption, and it is also required for decryption (remember this!).

The following is a screenshot of the data in the table:

The above insert statement has three fields, "Username", "Password" and "Encrypted Password". The AES_ENCRYPT() function requires a "key" to assist with encryption, and it is also required for decryption (remember this!).

The following is a screenshot of the data in the table:

Query encrypted data from the table

The query above uses the AES_DECRYPT() function. Here are the results:

In the above screenshot, we can see that the values ​​of the "pasword" and "decryptedpassword" fields are the same, that is, you have decrypted the user password.

Thank you for reading, I hope it can help you, thank you for your support of this site!

You may also be interested in:
  • Sharing of MD5 encryption algorithm implemented in Java, JavaScript, Oracle, and MySQL
  • MD5 encryption statement for mysql and mssql
  • Using XOR encryption algorithm in PHP MySQL application
  • MySQL encryption/compression functions
  • Detailed explanation of MySQL two-way encryption and decryption usage
  • MySQL whole table encryption solution keyring_file detailed explanation

<<:  Share 12 commonly used Loaders in Webpack (Summary)

>>:  How to upload the jar package to nexus via the web page

Recommend

How to reduce image size using Docker multi-stage build

This article describes how to use Docker's mu...

mysql is not an internal command error solution

The error "mysql is not an internal command&...

Several ways to connect tables in MySQL

The connection method in MySQL table is actually ...

Vue2/vue3 routing permission management method example

1. There are generally two methods for Vue routin...

Pure CSS3 to create page switching effect example code

The one I wrote before is too complicated, let’s ...

About the "occupational disease" of designers

I always feel that designers are the most sensiti...

Beginner's guide to building a website ⑥: Detailed usage of FlashFXP

Today I will introduce the most basic functions of...

How to obtain and use time in Linux system

There are two types of Linux system time. (1) Cal...

Summary of 6 solutions for implementing singleton mode in JS

Preface Today, I was reviewing the creational pat...

In-depth understanding of CSS @font-face performance optimization

This article mainly introduces common strategies ...

Comprehensive analysis of MySql master-slave replication mechanism

Table of contents Master-slave replication mechan...