我创建了以下自定义函数:
package co.hive.udf;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.*;
import org.apache.hadoop.hive.ql.exec.UDF;
public class encryptHivecolumn extends UDF {
private static final String ALGO = "AES";
private static final byte[] keyValue =
new byte[] { 'T', 'h', 'e', 'B', 'e', 's', 't',
'S', 'e', 'c', 'r','e', 't', 'K', 'e', 'y' };
public static String encrypt(String Data) throws Exception {
Key key = generateKey();
Cipher c = Cipher.getInstance(ALGO);
c.init(Cipher.ENCRYPT_MODE, key);
byte[] encVal = c.doFinal(Data.getBytes());
@SuppressWarnings("restriction")
String encryptedValue = new BASE64Encoder().encode(encVal);
return encryptedValue;
}
private static Key generateKey() throws Exception {
Key key = new SecretKeySpec(keyValue, ALGO);
return key;
}
}
从eclipse创建jar。我也从eclipse中添加了jar文件,它显示added to classpath,但当我创建临时函数时,它显示class not found。
1条答案
按热度按时间csbfibhn1#
我能够创建jar并运行它,但现在我得到了下面的错误。如果我只是运行select语句,它是正确加密的,但是当我从select创建表时,它在表中插入空值。详情请参见下文。如何避免CREATETABLEAS语句中列变为null的问题。
1 biopf4lrwbphdwrbisv4eg==null null kqcnitorf des moines null 2 qkxexqbmwz5y9nwjo4pdyq==null u6792wt1mz jefferson city null 3 hlb2ya9j+ayipkcqwkqbca==null sur6iqzwlj charleston null 4 ctljlq7d2+h+nf52lvqdja==null yemmnhuqca providence null 5 zgsopivwdya70f+qhuvsjg==null xe3bw5cjib juneau null 6 8ogof6opg38ceqrdczvbkwkwk==null null pqoxrqhycp巴吞鲁日null 7 kjwaxk7pxtcuoexqbd56dw==null IRKWOTQNR卡森市null 8 iyqaknygoo3hnvrnmaawqw==null 5tddmqaxrx普罗维登斯null 9 CXYNZFBCS0NQWWI5HJ07A==null otww4bdfvv raleigh null 10 jbxii6c24f+s9hiwo52ryg==null NIRNATIWO augusta null所用时间:0.058秒,获取时间:20行