电子签章信息&验证签名

电子签章信息 & 验证签名

获取OFD文档中的电子签章信息和验证签名

调用示例

public void testSealDetails() {
      KGOfdHummer hummer = null;
            try {
                   //创建文档编辑实例
                  hummer = KGOfdHummer.createInstance("D:/ofd/test.ofd", null);
                   //签章信息列表
                  OfdSignDetails signDetails = new OfdSignDetails();
                  hummer.addExecute(signDetails);
                  hummer.doExecute();
                  List signInfos = signDetails.getSignInfos();
                  for (SignInfo signInfo : signInfos) {
                        System.out.println(" 序号:" + signInfo.getSealInfo().getIndex());
                        System.out.println("------印章信息------");
                        System.out.println(signInfo.getSealInfo().getSealVid());
                        System.out.println(signInfo.getSealInfo().getSealID());
                        System.out.println(signInfo.getSealInfo().getType());
                        System.out.println(signInfo.getSealInfo().getSealName());
                        System.out.println(signInfo.getSealInfo().getValidStart());
                        System.out.println(signInfo.getSealInfo().getValidEnd());
                        System.out.println(signInfo.getSealInfo().getCreateDate());
                        System.out.println(signInfo.getSealInfo().getSignDate());
                        System.out.println(signInfo.getSealInfo().getUserName());
                        System.out.println("------印章信息------");
                        System.out.println("------证书信息------");
                        System.out.println("证书版本:" + signInfo.getCertificateStructure().getVersion());
                        System.out.println("序列号:" + signInfo.getCertificateStructure().getSerialNumber().getValue().toString(16));
                        System.out.println("算法标识:" + signInfo.getCertificateStructure().getSignatureAlgorithm().getObjectId().getId());
                        System.out.println("签发者:" + signInfo.getCertificateStructure().getIssuer());
                        System.out.println("开始时间:" + signInfo.getCertificateStructure().getStartDate().getTime());
                        System.out.println("结束时间:" + signInfo.getCertificateStructure().getEndDate().getTime());
                        System.out.println("主体名:" + signInfo.getCertificateStructure().getSubject());
                        DERBitString signature = signInfo.getCertificateStructure().getSignature();
                        String strSign = new String(Hex.encode(signature.getBytes()));
                        System.out.println("签名值:" + strSign);
                        SubjectPublicKeyInfo pukinfo = signInfo.getCertificateStructure().getSubjectPublicKeyInfo();
                        System.out.println("标识符:" + pukinfo.getAlgorithmId().getObjectId().getId());
                        byte[] byPuk = pukinfo.getPublicKeyData().getBytes();
                        String strPuk = new String(Hex.encode(byPuk));
                        System.out.println("公钥值:" + strPuk);
                        System.out.println("------证书信息------ ");
                        System.out.println("验证证书结果:" + signInfo.cerValid());
                        System.out.println("签证签名结果:" + signInfo.verifySign(signDetails));
                  }
            } catch (Exception e) {
e.printStackTrace();
            }
}

示例下载