본문 바로가기
IT

Sign Server.jsp

by 달남 2019. 12. 20.

<%@page
language="java" contentType="text/html; charset=UTF-8"
import="org.json.simple.JSONObject,
        java.security.PrivateKey, java.security.cert.X509Certificate,
        ksign.jce.util.Base64,
        ksign.jce.util.JCEUtil,
        ksign.jce.provider.pkcs.*"
%>
<%@page import="kr.or.kcue.com.util.EgovProperties"%>
<%
    String plainText = request.getParameter("plainText");
    String output = "";

    try {
        JCEUtil.initProvider();
// �������� ���ڼ��� �ϴ� ����̱� ������ ����� �������� Ű�� �����´�.
        //X509Certificate signCert = (X509Certificate)JCEUtil.readCertificate("C:/eclipse/eclipse_exbuilder6/workspace/HTML5/WebContent/certificate/class1/SVRZ1234567094_sig.cer");
        //PrivateKey signPriKey = JCEUtil.readPrivateKey("epkiTest!2", "C:/eclipse/eclipse_exbuilder6/workspace/HTML5/WebContent/certificate/class1/SVRZ1234567094_sig.key");

        String strCert =  EgovProperties.getProperty("Globals.certPath");
    String strPrivateKey =  EgovProperties.getProperty("Globals.privateKeyPath");

    X509Certificate signCert = (X509Certificate)JCEUtil.readCertificate(strCert);
    PrivateKey signPriKey = JCEUtil.readPrivateKey("epkiTest!2", strPrivateKey);
        
        SignedData signedData = new SignedData();
        signedData.setMessage(plainText.getBytes());
        byte[] signedBytes = signedData.generate(signCert, signPriKey, "SHA256");
        output = plainText;
        output = new String(signedBytes);
        output = new String(Base64.encode(signedBytes));
    } catch (Exception e) {
        output = e.toString();
    }

    JSONObject jsonObj = new JSONObject();
    jsonObj.put("out", output);
    //out.print(jsonObj.toString()); //소스코드 점검결과 조치 시작 19.12.02
%>

댓글