Home > Database > Mysql Tutorial > body text

Detailed explanation of MySQL encryption

迷茫
Release: 2017-03-26 13:50:00
Original
1545 people have browsed it

MySQL field encryption and decryption

  1. Encryption:

    aes_encrypt('admin','key')
Copy after login

2. Decryption :

  aes_decrypt(password,'key')
Copy after login

2. Two-way encryption uses a key to encrypt. When decrypting, only the person who knows the key can decrypt

Encryption: encode()

Decryption: decode()

Encode('123456' 'adfdgfdhggfh');

decode(password,'adfdgfdhggfh');

3.PASSWORD('123456')

Password encryption is irreversible

4.MD5('123456')

//UserDao 
public User login(Connection con,User user) throws Exception{
        User resultUser=null;
        String sql="select userName,AES_DECRYPT(password,'key') password from t_user where userName=? and AES_DECRYPT(PASSWORD,'key')=?";
        PreparedStatement pstmt=con.prepareStatement(sql);
        pstmt.setString(1, user.getUserName());
        pstmt.setString(2, user.getPassword());
        ResultSet rs=pstmt.executeQuery();
        if(rs.next()){
            resultUser=new User();
            resultUser.setUserName(rs.getString(1));
            resultUser.setPassword(rs.getString(2));
            System.out.println(resultUser.getPassword()+"^^^^^");
        }
        return resultUser;
    }
}
   
 //sql语句 
 insert into t_user (userName,password) values('admin',AES_ENCRYPT('123456','key'));  
 select userName,AES_DECRYPT(password,'key')password from t_user;
Copy after login

The above is the detailed content of Detailed explanation of MySQL encryption. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template