Home  >  Article  >  Database  >  Detailed explanation of MySQL encryption

Detailed explanation of MySQL encryption

迷茫
迷茫Original
2017-03-26 13:50:001526browse

MySQL field encryption and decryption

  1. Encryption:

    aes_encrypt('admin','key')

2. Decryption :

  aes_decrypt(password,'key')

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;

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!

Statement:
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