电子签章,就是给文件盖个章,哈哈,如果你也这么认为那就大错特错了。实际上不是这么简单,而是在盖章的同时隐藏了一个签名(加密)。
一般做电子签章都有电子签章服务器。需要知道电子签章服务器的ip和端口。
下面是java调用电子签章服务器代码,仅供参考。
1.依赖的jar
esspdf-client-1.4.1-SNAPSHOT.jar
jackson-module-jaxb-annotations-2.0.6.jar
jackson-all.jar
2.代码:
- ESSPDFClientTool essPDFClientTool = null;
- InputStream in = null;
- ByteArrayOutputStream outArr = new ByteArrayOutputStream();
- OutputStream out = null;
- try {
- String elePlyIP = DeploymentConfig.getProperty(DeploymentConfigConstants.ELEC_SIGN_IP);//获得电子签章IP
- String elePlyPort = DeploymentConfig.getProperty(DeploymentConfigConstants.ELEC_SIGN_PORT);//获得电子签章端口
- essPDFClientTool = new ESSPDFClientTool(elePlyIP,Integer.parseInt(elePlyPort));
- in = new FileInputStream(new File(filePath));
- int len;
- while ((len=in.read())!=-1) {
- outArr.write(len);
- outArr.flush();
- }
- ChannelMessage message = null;
- String[] rulesArr = rules.split(";");
- List<String> rulesList = new ArrayList<String>();
- if(rulesArr.length>1){
- rulesList = Arrays.asList(rulesArr);
- message = essPDFClientTool.pdfSign(rulesList, outArr.toByteArray());
- }else{
- message = essPDFClientTool.pdfSign(rules, outArr.toByteArray());
- }
- System.out.println("签章状态信息:" + message.getStatusInfo());
- if ("200".equals(message.getStatusCode())) {// 成功
- out = new FileOutputStream(filePath);
- byte[] signByte = message.getBody();
- out.write(signByte);
- out.flush();
- }else{
- System.out.println("==============电子签章服务器返回状态失败==================");
- throw new Exception("生成电子签章失败");
- }
- } catch (Exception e) {
- e.printStackTrace();
- throw new Exception("生成电子签章失败");
- }