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); } }