package com.qxueyou.scc.base.util;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.Logger;
|
|
import com.caucho.hessian.client.HessianProxyFactory;
|
//import com.qxueyou.scc.base.service.IConfigService;
|
|
/**
|
* RSA加解密--调用远程加解密服务
|
* @author 德虎
|
*
|
*/
|
public class RSAUtils {
|
|
private static Logger log = LogManager.getLogger(RSAUtils.class);
|
|
private static RSAClient client;
|
|
/**
|
* 构建远程RSA加解密客户端
|
*/
|
private static void buildClient() {
|
try {
|
String url = null;
|
HessianProxyFactory hessianFactory = new HessianProxyFactory();
|
client = (RSAClient) hessianFactory.create(RSAClient.class, url);
|
} catch (Exception e) {
|
log.error(e, e);
|
}
|
}
|
|
/**
|
* 调用远程加密服务对字符串加密
|
* @param string
|
* @return
|
*/
|
public static String encrypt(String string) {
|
if (client == null) {
|
buildClient();
|
}
|
if (StringUtils.isEmpty(string)) {
|
return "";
|
}
|
try {
|
return client.encrypt(string);
|
} catch (Exception e) {
|
log.error("加解密服务初始化错误:"+e.getMessage(), e);
|
}
|
return null;
|
}
|
|
/**
|
* 调用远程解密服务对密文字符串解决
|
* @param string
|
* @return
|
*/
|
public static String decrypt(String string) {
|
if (client == null) {
|
buildClient();
|
}
|
if (StringUtils.isEmpty(string)) {
|
return "";
|
}
|
try {
|
return client.decrypt(string);
|
} catch (Exception e) {
|
log.error(e, e);
|
}
|
return null;
|
}
|
|
/**
|
* Hessian本地接口
|
* @author user
|
*
|
*/
|
interface RSAClient {
|
String encrypt(String string);
|
String decrypt(String string);
|
}
|
|
}
|