mysql数据查询,对加密字段进行模糊查询

场景:我在模糊查询电话号码的时候,发现电话号码是进行过加密的,而传进来的参数却是明文的

明文参数:2352

在这里插入图片描述
数据库是加密的:
在这里插入图片描述
解决办法:
在这里插入图片描述

<if test="monitorManagerListParam.phoneNumber != null and monitorManagerListParam.phoneNumber != ''">
     AND   AES_DECRYPT(UNHEX( cmm.PHONE_NUMBER), "加密密钥") like CONCAT('%',#{monitorManagerListParam.phoneNumber},'%')
</if>

如果模糊搜索带中文,那需要如下代码:

在这里插入图片描述

<if test="monitorManagerListParam.keyWordThree != null and monitorManagerListParam.keyWordThree != ''">
        AND CAST(binary(AES_DECRYPT(UNHEX(cmm.MESSAGE),"加密密钥"))
        AS CHAR CHARACTER SET UTF8)
        LIKE CONCAT('%',#{monitorManagerListParam.keyWordThree},'%')
</if>

版权声明:本文为weixin_42691149原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。