浏览 1893 次
锁定老帖子 主题:itext解析pdf中签章文件的证书
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2015-09-11
目前系统中有一个需求,系统要求上传的pdf必须进行签章,上传后需要对pdf进行验签和拿到pdf章的证书的所有者, 拿到章证书的所有者代码如下 <pre name="code" class="java"> PdfReader reader = new PdfReader(pdfPath); AcroFields acroFields = reader.getAcroFields(); if (acroFields == null) { return result; } List<String> signatureNames = acroFields.getSignatureNames(); if (signatureNames == null || signatureNames.size() == 0) { return result; } reader.close(); for (String str : signatureNames) { PdfDictionary sigDict = acroFields.getSignatureDictionary(str); if (sigDict == null) { continue; } PdfName sub = sigDict.getAsName(PdfName.SUBFILTER); if (PdfName.ADBE_X509_RSA_SHA1.equals(sub)) { PdfString certStr = sigDict.getAsString(PdfName.CERT); if (certStr == null) { certStr = sigDict.getAsArray(PdfName.CERT).getAsString(0); } if (certStr == null) { continue; } X509CertParser certParser = new X509CertParser(); certParser.engineInit(new ByteArrayInputStream(certStr.getBytes())); Collection<Certificate> certs = certParser.engineReadAll(); if (certs == null || certs.size() == 0) { continue; } X509Certificate certificate = (X509Certificate) certs.iterator().next(); if (certificate == null) { continue; } X500Principal principal = certificate.getSubjectX500Principal(); if (principal == null) { continue; } LdapName ldapDN = new LdapName(principal.getName()); for (Rdn rdn : ldapDN.getRdns()) { if ("CN".equals(rdn.getType())) { result.add((String) rdn.getValue()); } } } }</pre> 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2015-12-06
|
|
返回顶楼 | |