派生自 projectDept/qhighschool

胡仁荣
2022-10-31 fe7381d6e8ec1f427408de0297ac7f41533202f6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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);
    }
 
}