Example usage for java.security.cert X509Certificate getSerialNumber

List of usage examples for java.security.cert X509Certificate getSerialNumber

Introduction

In this page you can find the example usage for java.security.cert X509Certificate getSerialNumber.

Prototype

public abstract BigInteger getSerialNumber();

Source Link

Document

Gets the serialNumber value from the certificate.

Usage

From source file:com.viettel.hqmc.DAO.FilesDAO.java

/**
 *
 * @return @throws IOException/*from w w w.  j av  a  2s.c  o m*/
 */
public String actionSignCAFile() throws IOException {
    boolean result = true;
    String base64Hash = "";
    String certSerial = "";
    String fileId = "";
    String outPutFileFinal = "";
    String fileName = "";
    String fileToSign = "";
    String errorCode = "";
    SignPdfFile pdfSig = new SignPdfFile();
    try {
        fileId = getRequest().getParameter("fileId");
        String rootCert = null, base64Certificate = null;
        Base64 decoder = new Base64();
        String certChain = new String(
                decoder.decode(getRequest().getParameter("cert").replace("_", "+").getBytes()), "UTF-8");
        String sToFind = getRequest().getParameter("signType");
        String path = getRequest().getParameter("path");
        String[] pathArr = path.split(";");
        fileToSign = pathArr[0];
        fileName = pathArr[1];
        String[] chain;
        try {
            chain = certChain.split(",");
            rootCert = chain[1];
            base64Certificate = chain[0];
        } catch (Exception ex) {
            LogUtil.addLog(ex);//binhnt sonar a160901
            errorCode = "SI_001";
            result = false;
        }
        if (base64Certificate == null) {
            errorCode = "SI_002";
            result = false;
        }
        X509Certificate x509Cert = null;
        X509Certificate x509CertChain = null;
        try {
            x509Cert = CertUtils.getX509Cert(base64Certificate);
            x509CertChain = CertUtils.getX509Cert(rootCert);
        } catch (Exception ex) {
            LogUtil.addLog(ex);//binhnt sonar a160901
            errorCode = "SI_003";
            result = false;
        }

        PDFServerClientSignature pdfSCS = new PDFServerClientSignature();
        ResourceBundle rb = ResourceBundle.getBundle("config");
        String TSA_LINK = rb.getString("tsaUrl");
        pdfSCS.setTSA_LINK(TSA_LINK);
        String checkOcspStr = rb.getString("checkOCSP");
        Long checkOCSP = Long.parseLong(checkOcspStr);
        try {
            certSerial = x509Cert.getSerialNumber().toString(16);
        } catch (Exception ex) {
            LogUtil.addLog(ex);//binhnt sonar a160901
            errorCode = "SI_004";
            result = false;
        }
        String filePath = rb.getString("sign_temp_plugin");
        File f = new File(filePath);
        if (!f.exists()) {
            f.mkdirs();
        }
        outPutFileFinal = filePath + fileName;
        CaUserDAOHE ca = new CaUserDAOHE();
        boolean checkCaUser = true;
        if (!ca.checkCaSerial("SerialNumber:[" + certSerial + "]")) {
            errorCode = "SI_005";
            result = false;
        }
        try {
            if (checkOCSP == 1l) {
                OCSP.RevocationStatus.CertStatus status = checkRevocationStatus((X509Certificate) x509Cert,
                        (X509Certificate) x509CertChain);
                if (status != OCSP.RevocationStatus.CertStatus.GOOD) {
                    errorCode = "SI_006";
                    result = false;
                }
            }
        } catch (Exception ex) {
            LogUtil.addLog(ex);//binhnt sonar a160901
            errorCode = "SI_007";
            result = false;
        }
        if (checkCaUser) {//u 16 07 29
            String folderPath = ResourceBundleUtil.getString("sign_image");
            String folderStampDN = ResourceBundleUtil.getString("directory");
            String linkImageSign = folderPath + getUserId() + ".png";
            String linkImageStamp = folderPath + "attp.png";
            CaUser cabo;
            CaUserDAOHE cadaohe = new CaUserDAOHE();
            List<CaUser> lstCabo = cadaohe.findCaUserBySerialUser("SerialNumber:[" + certSerial + "]",
                    getUserLogin());
            if (!lstCabo.isEmpty() && lstCabo != null) {
                cabo = lstCabo.get(0);
                folderStampDN += cabo.getSignature();
            }
            linkImageSign = linkImageStamp;
            if ((linkImageSign == null && "".equals(linkImageSign))
                    || (linkImageStamp == null && "".equals(linkImageStamp))
                    || (folderStampDN == null && "".equals(folderStampDN))) {
                errorCode = "SI_008";
                result = false;
            }
            try {
                if ("CBDN".equals(sToFind)) {
                    if (fileToSign == null && "".equals(fileToSign)) {
                        errorCode = "SI_009";
                        result = false;
                    }
                    sToFind = "<SI>";
                    SearchTextLocations ptl = new SearchTextLocations();
                    List local = ptl.searchLocation(sToFind, fileToSign, SearchTextLocations.SEARCH_TOPDOWN,
                            SearchTextLocations.FIND_ONE);
                    String location = "0;0;0";
                    int pageNumber, lx, ly;
                    if (local != null && local.size() > 0) {
                        location = local.get(0).toString();
                    }
                    String[] parts = location.split(";");
                    pageNumber = Integer.parseInt(parts[0]);
                    lx = (int) Float.parseFloat(parts[1]);
                    ly = (int) Float.parseFloat(parts[2]);
                    ly = convertLocation(ly);
                    base64Hash = pdfSig.createHash(fileToSign, outPutFileFinal, new Certificate[] { x509Cert },
                            pageNumber, folderStampDN, lx + 70, ly + 130, 120, 70, "DN");
                }
            } catch (Exception ex) {
                LogUtil.addLog(ex);//binhnt sonar a160901
                errorCode = "SI_012";
                result = false;
            }

        } else {
            errorCode = "SI_013";
            result = false;
        }
    } catch (JsonSyntaxException ex) {
        LogUtil.addLog(ex);//binhnt sonar a160901
        errorCode = "SI_014";
        result = false;
    } catch (Exception ex) {
        LogUtil.addLog(ex);//binhnt sonar a160901
        errorCode = "SI_015";
        System.out.println(ex.getMessage());
        result = false;
    } finally {

    }
    List resultMessage = new ArrayList();
    if (result) {
        HttpServletRequest req = getRequest();
        HttpSession session = req.getSession();
        session.setAttribute("PDFSignature", pdfSig);
        resultMessage.add("1");
        resultMessage.add("Lu d liu thnh cng");
        resultMessage.add(base64Hash);
        resultMessage.add(certSerial);
        resultMessage.add(fileId);
        resultMessage.add(outPutFileFinal);
        resultMessage.add(fileName);
    } else {
        resultMessage.add("0");
        resultMessage.add("Lu d liu khng thnh cng " + errorCode);
    }
    jsonDataGrid.setItems(resultMessage);
    return GRID_DATA;
}

From source file:com.viettel.hqmc.DAO.FilesDAO.java

public String actionSignCAForAA() throws IOException {
    boolean result = true;
    String base64Hash = "";
    //        String base64Hash0 = "";
    String certSerial = "";
    String outPutFileFinal = "";
    //        String outPutFileFinal2 = "";
    String fileId = "";
    String fileName = "";
    //        String fileName0 = "";
    String fileToSign = "";
    //        String fileToSign0 = "";
    String errorCode = "";
    SignPdfFile pdfSig = new SignPdfFile();
    //        SignPdfFile pdfSig0 = new SignPdfFile();
    try {//from  ww w. java2  s  .  c  om
        fileId = getRequest().getParameter("fileId");
        String rootCert = null, base64Certificate = null, certChain;
        Base64 decoder = new Base64();
        certChain = new String(decoder.decode(getRequest().getParameter("cert").replace("_", "+").getBytes()),
                "UTF-8");
        String sToFind = getRequest().getParameter("signType");
        String path = getRequest().getParameter("path");
        String[] pathArr = path.split(";");
        fileToSign = pathArr[0];
        fileName = pathArr[1];

        String[] chain;
        try {
            chain = certChain.split(",");
            rootCert = chain[1];
            base64Certificate = chain[0];
        } catch (Exception ex) {
            LogUtil.addLog(ex);//binhnt sonar a160901
            errorCode = "SI_001";
            result = false;
        }
        if (base64Certificate == null) {
            errorCode = "SI_002";
            result = false;
        }
        X509Certificate x509Cert = null;
        X509Certificate x509CertChain = null;
        try {
            x509Cert = CertUtils.getX509Cert(base64Certificate);
            x509CertChain = CertUtils.getX509Cert(rootCert);
        } catch (Exception ex) {
            LogUtil.addLog(ex);//binhnt sonar a160901
            errorCode = "SI_003";
            result = false;
        }

        PDFServerClientSignature pdfSCS = new PDFServerClientSignature();
        ResourceBundle rb = ResourceBundle.getBundle("config");
        String TSA_LINK = rb.getString("tsaUrl");
        pdfSCS.setTSA_LINK(TSA_LINK);
        String checkOcspStr = rb.getString("checkOCSP");
        Long checkOCSP = Long.parseLong(checkOcspStr);
        try {
            certSerial = x509Cert.getSerialNumber().toString(16);
        } catch (Exception ex) {
            LogUtil.addLog(ex);//binhnt sonar a160901
            errorCode = "SI_004";
            result = false;
        }
        String filePath = rb.getString("sign_temp_plugin");
        File f = new File(filePath);
        if (!f.exists()) {
            f.mkdirs();
        }
        outPutFileFinal = filePath + fileName;
        //            outPutFileFinal2 = filePath + fileName0;
        CaUserDAOHE ca = new CaUserDAOHE();
        boolean checkCaUser = true;
        if (!ca.checkCaSerial("SerialNumber:[" + certSerial + "]")) {
            errorCode = "SI_005";
            result = false;
        }
        try {
            if (checkOCSP == 1l) {
                OCSP.RevocationStatus.CertStatus status = checkRevocationStatus((X509Certificate) x509Cert,
                        (X509Certificate) x509CertChain);
                if (status != OCSP.RevocationStatus.CertStatus.GOOD) {
                    errorCode = "SI_006";
                    result = false;
                }
            }
        } catch (Exception ex) {
            LogUtil.addLog(ex);//binhnt sonar a160901
            errorCode = "SI_007";
            result = false;
        }
        if (checkCaUser) {
            String folderPath = ResourceBundleUtil.getString("sign_image");
            String linkImageSign = folderPath + getUserId() + ".png";
            String linkImageStamp = folderPath + "attpStamp.png";
            if ((linkImageSign == null && "".equals(linkImageSign))
                    || (linkImageStamp == null && "".equals(linkImageStamp))) {
                errorCode = "SI_008";
                result = false;
            }
            try {
                if ("PDHS".equals(sToFind)) {
                    if (fileToSign == null && "".equals(fileToSign)) {
                        errorCode = "SI_009";
                        result = false;
                    }
                    sToFind = "<SI>";
                    SearchTextLocations ptl = new SearchTextLocations();
                    List local = ptl.searchLocation(sToFind, fileToSign, SearchTextLocations.SEARCH_TOPDOWN,
                            SearchTextLocations.FIND_ONE);
                    String location = "0;0;0";
                    int pageNumber, lx, ly;
                    if (local != null && local.size() > 0) {
                        location = local.get(0).toString();
                    }
                    String[] parts = location.split(";");
                    pageNumber = Integer.parseInt(parts[0]);
                    lx = (int) Float.parseFloat(parts[1]);
                    ly = (int) Float.parseFloat(parts[2]);
                    ly = convertLocation(ly);
                    base64Hash = pdfSig.createHash(fileToSign, outPutFileFinal, new Certificate[] { x509Cert },
                            pageNumber, linkImageSign, lx + 70, ly + 130, 120, 70, "LD");
                }
                if ("PDHS_VT".equals(sToFind)) {
                    // ky van thu
                    if (fileToSign == null && "".equals(fileToSign)) {
                        errorCode = "SI_010";
                        result = false;
                    }
                    String sToFindtemp = "<SI>";
                    SearchTextLocations ptl = new SearchTextLocations();
                    List local = ptl.searchLocation(sToFindtemp, fileToSign, SearchTextLocations.SEARCH_TOPDOWN,
                            SearchTextLocations.FIND_ONE);
                    String location = "0;0;0";
                    int pageNumber, lx, ly;
                    if (local != null && local.size() > 0) {
                        location = local.get(0).toString();
                    }
                    String[] parts = location.split(";");
                    pageNumber = Integer.parseInt(parts[0]);
                    lx = (int) Float.parseFloat(parts[1]);
                    ly = (int) Float.parseFloat(parts[2]);
                    ly = convertLocation(ly);
                    base64Hash = pdfSig.createHash(fileToSign, outPutFileFinal, new Certificate[] { x509Cert },
                            pageNumber, linkImageStamp, lx + 23, ly + 115, 90, 90, "VT");
                }
                if ("CVBS_VT".equals(sToFind)) {
                    // ky van thu
                    if (fileToSign == null && "".equals(fileToSign)) {
                        errorCode = "SI_026";
                        result = false;
                    }
                    String sToFindtemp = "<SI>";
                    SearchTextLocations ptl = new SearchTextLocations();
                    List local = ptl.searchLocation(sToFindtemp, fileToSign, SearchTextLocations.SEARCH_TOPDOWN,
                            SearchTextLocations.FIND_ONE);
                    String location = "0;0;0";
                    int pageNumber, lx, ly;
                    if (local != null && local.size() > 0) {
                        location = local.get(0).toString();
                    }
                    String[] parts = location.split(";");
                    pageNumber = Integer.parseInt(parts[0]);
                    lx = (int) Float.parseFloat(parts[1]);
                    ly = (int) Float.parseFloat(parts[2]);
                    ly = convertLocation(ly);
                    base64Hash = pdfSig.createHash(fileToSign, outPutFileFinal, new Certificate[] { x509Cert },
                            pageNumber, linkImageStamp, lx + 23, ly + 130, 90, 90, "VT");
                }

                if ("CVBS".equals(sToFind)) {
                    // ky lanh dao
                    if (fileToSign == null && fileToSign.equals("")) {
                        errorCode = "SI_011";
                        result = false;
                    }
                    String sToFindtemp = "<SI>";
                    SearchTextLocations ptl = new SearchTextLocations();
                    List local = ptl.searchLocation(sToFindtemp, fileToSign,
                            SearchTextLocations.SEARCH_BOTTOMUP, SearchTextLocations.FIND_ONE);
                    String location = "0;0;0";
                    int pageNumber, lx, ly;
                    if (local != null && local.size() > 0) {
                        location = local.get(0).toString();
                    }
                    String[] parts = location.split(";");
                    pageNumber = Integer.parseInt(parts[0]);
                    lx = (int) Float.parseFloat(parts[1]);
                    ly = (int) Float.parseFloat(parts[2]);
                    ly = convertLocation(ly);
                    base64Hash = pdfSig.createHash(fileToSign, outPutFileFinal, new Certificate[] { x509Cert },
                            pageNumber, linkImageSign, lx + 80, ly + 150, 120, 70, "LD");
                }
            } catch (Exception ex) {
                LogUtil.addLog(ex);//binhnt sonar a160901
                System.out.println("ERROR SI_012|" + ex.getMessage());
                errorCode = "SI_012";
                result = false;
            }

        } else {
            errorCode = "SI_013";
            result = false;
        }
    } catch (JsonSyntaxException ex) {
        LogUtil.addLog(ex);//binhnt sonar a160901
        errorCode = "SI_014";
        result = false;
    } catch (Exception ex) {
        LogUtil.addLog(ex);//binhnt sonar a160901
        errorCode = "SI_015";
        result = false;
    } finally {

    }
    List resultMessage = new ArrayList();
    if (result) {
        HttpServletRequest req = getRequest();
        HttpSession session = req.getSession();
        session.setAttribute("PDFSignature", pdfSig);
        //            session.setAttribute("PDFSignature2", pdfSig0);
        resultMessage.add("1");
        resultMessage.add("Lu d liu thnh cng");
        resultMessage.add(base64Hash);
        resultMessage.add(certSerial);
        resultMessage.add(fileId);
        resultMessage.add(outPutFileFinal);
        resultMessage.add(fileName);
        //            resultMessage.add(base64Hash0);
        //            resultMessage.add(outPutFileFinal2);
        //            resultMessage.add(fileName0);
    } else {
        resultMessage.add("0");
        resultMessage.add("Lu d liu khng thnh cng " + errorCode);
    }
    jsonDataGrid.setItems(resultMessage);
    return GRID_DATA;
}

From source file:com.viettel.hqmc.DAO.FilesDAO.java

public String actionSignCA() throws IOException {
    boolean result = true;
    String base64Hash = "";
    String base64Hash0 = "";
    String certSerial = "";
    String fileId = "";
    String outPutFileFinal = "";
    String outPutFileFinal2 = "";
    String fileName = "";
    String fileName0 = "";
    String fileToSign = "";
    String fileToSign0 = "";
    String errorCode = "";
    SignPdfFile pdfSig = new SignPdfFile();
    SignPdfFile pdfSig0 = new SignPdfFile();
    try {// w  ww . ja  v a2s  .  c om
        fileId = getRequest().getParameter("fileId");
        String rootCert, base64Certificate, certChain;
        Base64 decoder = new Base64();
        certChain = new String(decoder.decode(getRequest().getParameter("cert").replace("_", "+").getBytes()),
                "UTF-8");
        String sToFind = getRequest().getParameter("signType");
        String path = getRequest().getParameter("path");
        String[] pathArr = path.split(";");
        fileToSign = pathArr[0];
        fileName = pathArr[1];
        if ("PDHS".equals(sToFind) || "PDHS_VT".equals(sToFind)) {
            fileToSign0 = pathArr[2];
            fileName0 = pathArr[3];
        }
        String[] chain;
        try {
            chain = certChain.split(",");
            rootCert = chain[1];
            base64Certificate = chain[0];
        } catch (Exception ex) {
            base64Certificate = null;
            LogUtil.addLog(ex);//binhnt sonar a160901
            errorCode = "SI_001";
            rootCert = "";
            result = false;
        }
        // hieptq update 150615
        if (base64Certificate == null) {
            errorCode = "SI_002";
            result = false;
        }
        X509Certificate x509Cert = null;
        X509Certificate x509CertChain = null;
        try {
            x509Cert = CertUtils.getX509Cert(base64Certificate);
            x509CertChain = CertUtils.getX509Cert(rootCert);
        } catch (Exception ex) {
            LogUtil.addLog(ex);//binhnt sonar a160901
            errorCode = "SI_003";
            result = false;
        }

        PDFServerClientSignature pdfSCS = new PDFServerClientSignature();
        ResourceBundle rb = ResourceBundle.getBundle("config");
        String TSA_LINK = rb.getString("tsaUrl");
        pdfSCS.setTSA_LINK(TSA_LINK);
        String checkOcspStr = rb.getString("checkOCSP");
        Long checkOCSP = Long.parseLong(checkOcspStr);
        try {
            certSerial = x509Cert.getSerialNumber().toString(16);
        } catch (Exception ex) {
            LogUtil.addLog(ex);//binhnt sonar a160901
            errorCode = "SI_004";
            result = false;
        }
        // hieptq update 160615 - check serial        
        String filePath = rb.getString("sign_temp_plugin");
        File f = new File(filePath);
        if (!f.exists()) {
            f.mkdirs();
        }
        outPutFileFinal = filePath + fileName;
        outPutFileFinal2 = filePath + fileName0;
        CaUserDAOHE ca = new CaUserDAOHE();
        //CaUser caur = null;
        boolean checkCaUser = true;
        if (!ca.checkCaSerial("SerialNumber:[" + certSerial + "]")) {
            errorCode = "SI_005";
            result = false;
        }
        try {
            if (checkOCSP == 1l) {
                OCSP.RevocationStatus.CertStatus status = checkRevocationStatus((X509Certificate) x509Cert,
                        (X509Certificate) x509CertChain);
                if (status != OCSP.RevocationStatus.CertStatus.GOOD) {
                    errorCode = "SI_006";
                    result = false;
                }
            }
        } catch (Exception ex) {
            LogUtil.addLog(ex);//binhnt sonar a160901
            errorCode = "SI_007";
            result = false;
        }
        if (checkCaUser) {
            String folderPath = ResourceBundleUtil.getString("sign_image");
            //String separator = ResourceBundleUtil.getString("separator");
            String linkImageSign = folderPath + getUserId() + ".png";
            String linkImageStamp = folderPath + "attpStamp.png";
            if ((linkImageSign == null && "".equals(linkImageSign))
                    || (linkImageStamp == null && "".equals(linkImageStamp))) {
                errorCode = "SI_008";
                result = false;
            }
            try {
                if (sToFind.equals("PDHS")) {
                    // ky lanh dao
                    if (fileToSign == null && "".equals(fileToSign)
                            || fileToSign0 == null && "".equals(fileToSign0)) {
                        errorCode = "SI_009";
                        result = false;
                    }
                    sToFind = "<SI>";
                    SearchTextLocations ptl = new SearchTextLocations();
                    List local = ptl.searchLocation(sToFind, fileToSign, SearchTextLocations.SEARCH_TOPDOWN,
                            SearchTextLocations.FIND_ONE);
                    String location = "0;0;0";
                    int pageNumber, lx, ly;
                    if (local != null && local.size() > 0) {
                        location = local.get(0).toString();
                    }
                    String[] parts = location.split(";");
                    pageNumber = Integer.parseInt(parts[0]);
                    lx = (int) Float.parseFloat(parts[1]);
                    ly = (int) Float.parseFloat(parts[2]);
                    ly = convertLocation(ly);
                    base64Hash = pdfSig.createHash(fileToSign, outPutFileFinal, new Certificate[] { x509Cert },
                            pageNumber, linkImageSign, lx + 70, ly + 130, 120, 70, "LD");
                    SearchTextLocations ptl2 = new SearchTextLocations();
                    List local2 = ptl2.searchLocation(sToFind, fileToSign0, SearchTextLocations.SEARCH_TOPDOWN,
                            SearchTextLocations.FIND_ONE);
                    String location2 = "0;0;0";
                    if (local2 != null && local2.size() > 0) {
                        location2 = local2.get(0).toString();
                    }
                    String[] parts2 = location2.split(";");
                    pageNumber = Integer.parseInt(parts2[0]);
                    int lx1 = (int) Float.parseFloat(parts2[1]);
                    int ly1 = (int) Float.parseFloat(parts2[2]);
                    ly1 = convertLocation(ly1);
                    base64Hash0 = pdfSig0.createHash(fileToSign0, outPutFileFinal2,
                            new Certificate[] { x509Cert }, pageNumber, linkImageSign, lx1 + 70, ly1 + 130, 120,
                            70, "LD");

                }
                if ("PDHS_VT".equals(sToFind)) {
                    // ky van thu
                    if (fileToSign == null && "".equals(fileToSign)
                            || fileToSign0 == null && "".equals(fileToSign0)) {
                        errorCode = "SI_010";
                        result = false;
                    }
                    String sToFindtemp = "<SI>";
                    SearchTextLocations ptl = new SearchTextLocations();
                    List local = ptl.searchLocation(sToFindtemp, fileToSign, SearchTextLocations.SEARCH_TOPDOWN,
                            SearchTextLocations.FIND_ONE);
                    String location = "0;0;0";
                    int pageNumber, lx, ly;
                    if (local != null && local.size() > 0) {
                        location = local.get(0).toString();
                    }
                    String[] parts = location.split(";");
                    pageNumber = Integer.parseInt(parts[0]);
                    lx = (int) Float.parseFloat(parts[1]);
                    ly = (int) Float.parseFloat(parts[2]);
                    ly = convertLocation(ly);
                    base64Hash = pdfSig.createHash(fileToSign, outPutFileFinal, new Certificate[] { x509Cert },
                            pageNumber, linkImageStamp, lx + 23, ly + 115, 90, 90, "VT");
                    SearchTextLocations ptl2 = new SearchTextLocations();
                    List local2 = ptl2.searchLocation(sToFindtemp, fileToSign0,
                            SearchTextLocations.SEARCH_TOPDOWN, SearchTextLocations.FIND_ONE);
                    String location2 = "0;0;0";
                    if (local != null && local2.size() > 0) {
                        location2 = local2.get(0).toString();
                    }
                    String parts2[] = location2.split(";");
                    pageNumber = Integer.parseInt(parts2[0]);
                    int lx1 = (int) Float.parseFloat(parts2[1]);
                    int ly1 = (int) Float.parseFloat(parts2[2]);
                    ly1 = convertLocation(ly1);
                    base64Hash0 = pdfSig0.createHash(fileToSign0, outPutFileFinal2,
                            new Certificate[] { x509Cert }, pageNumber, linkImageStamp, lx1 + 23, ly1 + 115, 90,
                            90, "VT");

                }
                if ("CVBS_VT".equals(sToFind)) {
                    // ky van thu
                    if (fileToSign == null && "".equals(fileToSign)
                            || fileToSign0 == null && "".equals(fileToSign0)) {
                        errorCode = "SI_026";
                        result = false;
                    }
                    String sToFindtemp = "<SI>";
                    SearchTextLocations ptl = new SearchTextLocations();
                    List local = ptl.searchLocation(sToFindtemp, fileToSign, SearchTextLocations.SEARCH_TOPDOWN,
                            SearchTextLocations.FIND_ONE);
                    String location = "0;0;0";
                    int pageNumber, lx, ly;
                    if (local != null && local.size() > 0) {
                        location = local.get(0).toString();
                    }
                    String[] parts = location.split(";");
                    pageNumber = Integer.parseInt(parts[0]);
                    lx = (int) Float.parseFloat(parts[1]);
                    ly = (int) Float.parseFloat(parts[2]);
                    ly = convertLocation(ly);
                    base64Hash = pdfSig.createHash(fileToSign, outPutFileFinal, new Certificate[] { x509Cert },
                            pageNumber, linkImageStamp, lx + 23, ly + 130, 90, 90, "VT");
                }

                if ("CVBS".equals(sToFind)) {
                    // ky lanh dao
                    if (fileToSign == null && "".equals(fileToSign)) {
                        errorCode = "SI_011";
                        result = false;
                    }
                    String sToFindtemp = "<SI>";
                    SearchTextLocations ptl = new SearchTextLocations();
                    List local = ptl.searchLocation(sToFindtemp, fileToSign,
                            SearchTextLocations.SEARCH_BOTTOMUP, SearchTextLocations.FIND_ONE);
                    String location = "0;0;0";
                    int pageNumber, lx, ly;
                    if (local != null && local.size() > 0) {
                        location = local.get(0).toString();
                    }
                    String[] parts = location.split(";");
                    pageNumber = Integer.parseInt(parts[0]);
                    lx = (int) Float.parseFloat(parts[1]);
                    ly = (int) Float.parseFloat(parts[2]);
                    ly = convertLocation(ly);
                    base64Hash = pdfSig.createHash(fileToSign, outPutFileFinal, new Certificate[] { x509Cert },
                            pageNumber, linkImageSign, lx + 80, ly + 150, 120, 70, "LD");

                }
            } catch (Exception ex) {
                LogUtil.addLog(ex);//binhnt sonar a160901
                System.out.println("ERROR SI_012|" + ex.getMessage());
                errorCode = "SI_012";
                result = false;
            }

        } else {
            errorCode = "SI_013";
            result = false;
        }
    } catch (JsonSyntaxException ex) {
        LogUtil.addLog(ex);//binhnt sonar a160901
        errorCode = "SI_014";
        result = false;
    } catch (Exception ex) {
        LogUtil.addLog(ex);//binhnt sonar a160901
        errorCode = "SI_015";
        ex.printStackTrace();
        //            System.out.println(ex.getMessage());
        result = false;
    } finally {

    }
    List resultMessage = new ArrayList();
    if (result) {
        HttpServletRequest req = getRequest();
        HttpSession session = req.getSession();
        session.setAttribute("PDFSignature", pdfSig);
        session.setAttribute("PDFSignature2", pdfSig0);
        resultMessage.add("1");
        resultMessage.add("Lu d liu thnh cng");
        resultMessage.add(base64Hash);
        resultMessage.add(certSerial);
        resultMessage.add(fileId);
        resultMessage.add(outPutFileFinal);
        resultMessage.add(fileName);
        resultMessage.add(base64Hash0);
        resultMessage.add(outPutFileFinal2);
        resultMessage.add(fileName0);
    } else {
        resultMessage.add("0");
        resultMessage.add("Lu d liu khng thnh cng " + errorCode);
    }
    jsonDataGrid.setItems(resultMessage);
    return GRID_DATA;
}