Database ciphertext storage - mybatis automatic encryption and decryption plug-in

Because the fields involving personal privacy information are prevented from leaking, the first task is encryption, so it needs to be encrypted and stored directly in the source-database.

   Source code please click here  

   Intercept implementation based on parameter processing and result processing

  add dependencies

    <dependency>
         <groupId>com.lmx</groupId>
         <artifactId>common-util</artifactId>
         <version>{lastVersion}</version>
    </dependency>

 bean configuration

    AesService aseService = new DefaultAesServiceImpl("base64编码并且长度=16的秘钥串")


    @Bean
    public ParameterInterceptor encAndDecryptFilter() {
        return new ParameterInterceptor (aseService );
    }



    @Bean
    public ResultInterceptor encAndDecryptFilter() {
        return new ResultInterceptor (aseService );/
    }
    
    
    @Data
    public class User implements Serializable {
        ..................
        //声明该字段需要更新字段加密,查询自动解密
        @EncDecrypt
        private String qq;
    }
    
    
    


  Flexible support for writing multiple parameters:

    User qryByQq(@EncDecrypt @Param("qq") String qq);

    User qryByTel(@Param("obj") User user);
    
    User qryByTel(User user);


    
    Encryption and decryption functions for easy SQL query:    

    select to_base64(AES_ENCRYPT("285980382",from_base64("base64编码并且长度=16的秘钥串"))) a;

   
    select AES_DECRYPT(from_base64("上一步的密文"),from_base64("base64编码并且长度=16的秘钥串")) ;

    Use the above sql and secret key to brush the library, which is in line with out-of-the-box use
    
    

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324075721&siteId=291194637