Commit ce4c8090 authored by 王亮's avatar 王亮

add crypt converter.

parent b69bf223
package cn.quantgroup.xyqb.util;
import cn.quantgroup.security.AESEncryption;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import org.apache.commons.lang3.StringUtils;
public class AESUtils {
public static AESEncryption encryption;
/**
* V2方法不再考虑历史数据兼容问题
*
* @param plainValue 明文
* @return 密文
*/
public static String encryptV2(final String plainValue) {
if (StringUtils.isNotEmpty(plainValue)) {
return encryption().encryptBase64(plainValue);
}
return plainValue;
}
/**
* V2方法不再考虑历史数据兼容问题
*
* @param cipherValue 明文
* @return 密文
*/
public static String decryptV2(String cipherValue) {
return StringUtils.isNotEmpty(cipherValue) ? encryption().decryptBase64(cipherValue)
: cipherValue;
}
public static AESEncryption encryption() {
if (encryption == null) {
Config config = ConfigService.getAppConfig();
String key = config.getProperty("encrypt.key", "");
String iv = config.getProperty("encrypt.iv", "");
encryption = new AESEncryption(key, iv, true);
}
return encryption;
}
}
package cn.quantgroup.xyqb.util.encrypt;
import cn.quantgroup.xyqb.util.AESUtils;
import javax.persistence.AttributeConverter;
public class CryptConverter implements AttributeConverter<String, String> {
@Override
public String convertToDatabaseColumn(String attribute) {
return AESUtils.encryptV2(attribute);
}
@Override
public String convertToEntityAttribute(String dbData) {
return AESUtils.decryptV2(dbData);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment