在使用java进行udf函数编写的过程中发现,insert select语句 和select 语句在相同的前提条件下,加密出来的中文结果不一致。insert select加密后的数据经解密发现数据乱码。
代码示例如下:
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package com.sm.hive;
import com.sm.util.Sm4Util;
import java.nio.charset.StandardCharsets;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.udf.generic.

在Hive中使用自定义UDF实现SM4加密时,发现insert select语句加密中文后解密出现乱码,而直接select时正常。通过排查数据编码、加密数据本身及代码问题,最终取消hutool包引用并调整加密数据格式,解决了乱码问题。问题原因未深究,供遇到类似问题者参考。
最低0.47元/天 解锁文章
2129





