PDFSign.js 是一个用于在浏览器中签名 PDF 文档的 JavaScript 库。签名只在浏览器中进行,且不会通过网络发送私钥或密码。
API 非常简单:
signed-pdf = PDFSIGN.signpdf(pdf, p12-cert, p12-cert-password);
下面是一个示例网站。在此示例中,可以设置证书(例如,support / mycert-1-alt.p12),设置密码“1234”,并添加 PDF 文件。 PDF 将使用证书签署,Adobe Reader 将显示 PDF 已签署但不受信任(其为自签名证书)。 “Create a PDF and output base64” 按钮将采用 base64 编码文件,并在浏览器中输出一个 base64 PDF 文档。
<!DOCTYPE html> <html> <head> <title>PDFSign</title> <meta charset="utf-8"/> <!-- inject:js --> <!-- endinject --> </head> <body> <table> <tr> <th>p12 Certificate</th><th>p12 Password</th><th>PDF file</th> </tr><tr> <td><input type="file" id="cert" name="cert[]" multiple /></td> <td><input type="password" id="pass" name="pass" /></td> <td><input type="file" id="pdf" name="pdf[]" multiple /></td> </tr> </table> <br/><br/> <button onclick="document.location = 'data:application/pdf;base64,'+encodeBase64(PDFSIGN.signpdf(pdfmini, cert, '1234', new Date(1450365030990)));">Create a PDF and output base64</button> <script type="text/javascript"> var BASE64_MARKER = ';base64,'; var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; var pdfmini = convertDataURIToBinary('data:application/pdf;base64,JVBERi0xLjQKJcKlwrEKCgoKMSAwIG9iagogIDw8IC9UeXBlIC9DYXRhbG9nCiAgICAgL1BhZ2VzIDIgMCBSCiAgPj4KZW5kb2JqCgoyIDAgb2JqCiAgPDwgL1R5cGUgL1BhZ2VzCiAgICAgL0tpZHMgWzMgMCBSXQogICAgIC9Db3VudCAxCiAgICAgL01lZGlhQm94IFswIDAgMzAwIDE0NF0KICA+PgplbmRvYmoKCjMgMCBvYmoKICA8PCAgL1R5cGUgL1BhZ2UKICAgICAgL1BhcmVudCAyIDAgUgogICAgICAvUmVzb3VyY2VzCiAgICAgICA8PCAvRm9udAogICAgICAgICAgIDw8IC9GMQogICAgICAgICAgICAgICA8PCAvVHlwZSAvRm9udAogICAgICAgICAgICAgICAgICAvU3VidHlwZSAvVHlwZTEKICAgICAgICAgICAgICAgICAgL0Jhc2VGb250IC9UaW1lcy1Sb21hbgogICAgICAgICAgICAgICA+PgogICAgICAgICAgID4+CiAgICAgICA+PgogICAgICAvQ29udGVudHMgNCAwIFIKICA+PgplbmRvYmoKCjQgMCBvYmoKICA8PCAvTGVuZ3RoIDU1ID4+CnN0cmVhbQogIEJUCiAgICAvRjEgMTggVGYKICAgIDAgMCBUZAogICAgKEhlbGxvIFdvcmxkKSBUagogIEVUCmVuZHN0cmVhbQplbmRvYmoKCnhyZWYKMCA1CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAxOCAwMDAwMCBuIAowMDAwMDAwMDc3IDAwMDAwIG4gCjAwMDAwMDAxNzggMDAwMDAgbiAKMDAwMDAwMDQ1NyAwMDAwMCBuIAp0cmFpbGVyCiAgPDwgIC9Sb290IDEgMCBSCiAgICAgIC9TaXplIDUKICA+PgpzdGFydHhyZWYKNTY1CiUlRU9GCg=='); var cert = convertDataURIToBinary('data:application/x-pkcs12;base64,MIIQiQIBAzCCEE8GCSqGSIb3DQEHAaCCEEAEghA8MIIQODCCBm8GCSqGSIb3DQEHBqCCBmAwggZcAgEAMIIGVQYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQYwDgQI8pLaAKEKIA8CAggAgIIGKCZ3XA74Leic0KBofHqEzX6XptlHCLhoI55oV5XKFYpMQ4An5DiAtkrLJpL8S0LjXUMyk/rOYrTM4J5mXo8RteIQ2WPW68NWWcaq4DWvE5jsldNKdCYLpYg4r7EHoLU4AoC/07K4ZTMS8SzrcNPES62PWnLbqlSciDf82+TcGPlfxYwiHKTLnnJ/P6vH8DJB30D/+6qKP7i/ADPuSl8o3leQO4TTtq3r/9roGG+Q5Ml7un/PPAWmmncXi+cGl0kbUS9Vqi6Ckf2CQNX26MADuN1ozEsjmw64FB8oPsecLqwENardK0z9t7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7wQOS4ZZuSF0apAxY6OuTzmetNxc5pvMeOGwEYJSAUoMWQBrzG7wnZJL5+qc1L43/SKqlmPZmioO9FIm/EumjkHDP/+IZ8vDVChCiL2OANXe9muwTr+img2S5ev3SWNHJFInMgKhNOkgZtIhJASr6Eb6INB1wRb+EFp+hfKCSseUYhIBuUcA9T/1Cfd10sSYtqa6J4f2BUKJlfKgtsf5elK0h5ORHnsFyDSzTJc/cWSWTIgAtiNkGEoUtoeQFF1/1PzW7ObjmNzeO6+3/UN4Apjy42pHZZfjqP+Zv5I8UWFkCsbN834qERFTbVkZc1qfY48K8mfhDzM+7TySw9SvMZ0zosQFlYJ0OnUXp7ULj4iXM2LzEyocYK4zoo48+Qt1KHYl2If7ylWAO7/g6nLOInAlvhO/AilZu8PozHGn6S6JBdLsHYVMGj9C5Vh8WhB+ocXkGgJ5Uth/e3aCW6ZIG1fGf7exAkTS4ctKYf4DCI8FtDIOQiI30K9SB0WypYHcNOn1x94dtaVbdu6eCuR6MrmJgM1IaEYl3J87Z9mD3LWeCrrLLgpPROd+Z3qJvnsNFeFsZ8Lp35TXGI6UrsL+vgsYMQOT4TIFx7Zh/ZwQIdm3SaAsO5ZV4HdxVHIl1dTYJ4cqQAnwu94S3fMewg3o5UpZY8LxrCdu999z2LeLKDjouvElkCDvZ1GTNRKrd4yE8RGCuHJNPZxm3Vu4cRpZ5IpmpB/wid9gmsMNA7ssUf29thCxvDV4DjNNY1jhiGuUwMiZbYv8OTElMCMGCSqGSIb3DQEJFTEWBBTDfaKCuquWg83uugmF2R/HxCdm7TAxMCEwCQYFKw4DAhoFAAQUFKlnEqs2Et+Q6zeUuDUmrRbxm24ECDCnONNEU+P/AgIIAA=='); function convertDataURIToBinary(dataURI) { var base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length; var base64 = dataURI.substring(base64Index); return decodeBase64(base64); } /** * * Base64 encode / decode * http://www.webtoolkit.info/ * * window.atob -> browser/node.js dependant, this works on any engine * **/ function encodeBase64(input) { var output = ""; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; while (i < input.length) { chr1 = input[i++]; chr2 = input[i++]; chr3 = input[i++]; enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4); } return output; } function decodeBase64(input) { var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; var size = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); var uint8 = new Uint8Array(input.length); while (i < input.length) { enc1 = keyStr.indexOf(input.charAt(i++)); enc2 = keyStr.indexOf(input.charAt(i++)); enc3 = keyStr.indexOf(input.charAt(i++)); enc4 = keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; uint8[size++] = (chr1 & 0xff); if (enc3 !== 64) { uint8[size++] = (chr2 & 0xff); } if (enc4 !== 64) { uint8[size++] = (chr3 & 0xff); } } return uint8.subarray(0,size); } var certInput = new Uint8Array(); function handleFileSelect1(evt) { var file = evt.target.files[0]; var reader = new FileReader(); reader.onload = function (event) { certInput = event.target.result; } reader.readAsArrayBuffer(file); } document.getElementById('cert').addEventListener('change', handleFileSelect1, false); function handleFileSelect2(evt) { var file = evt.target.files[0]; var reader = new FileReader(); reader.onload = function (event) { var data = event.target.result; pdfSigned = PDFSIGN.signpdf(data, certInput, document.getElementById('pass').value); createPDFDownload(pdfSigned, 'pdfSigned.pdf'); } reader.readAsArrayBuffer(file); } document.getElementById('pdf').addEventListener('change', handleFileSelect2, false); function createPDFDownload(array, filename) { var a = window.document.createElement('a'); a.href = window.URL.createObjectURL(new Blob([array], { type: 'application/pdf' })); a.download = filename; // Append anchor to body. document.body.appendChild(a); a.click(); // Remove anchor from body document.body.removeChild(a); } </script> </body> </html>
然而,我想使用相同的文件,这意味着我不再假装复制PDF了。我要抓取文档,签名,并覆盖原来的。 由于我了解到让FileInputStream和FileOutputStream指向同一个文件不是一个好主意,所以我只是尝试使用file类。 我尝试了以下操作:
我有一个问题与数字签名PDF文件已标记为PDF/A-3A兼容。使用PDFBox(最新版本,2.0.24)最终在Adobe Acrobat中获得无效签名,而使用iText7(最新版本)获得有效签名。目标是获得符合PAdES LTV的签名。 我的流程如下(使用PDFBox和iText7): 打开PDF,创建用于签名的散列(要签名的数据) 我呼叫第三方服务以取回数字签名 在服务响应中,我还获得了OCSP
如何使用Perl中的数字签名对pdf文件进行签名?我能够提取pdf的内容,并生成签名字符串通过 #$Content->要签名的pdf内容
我需要将一个使用iText5进行PDF签名验证/创建的Java程序移植到iText7。 旧代码显然不能按原样工作,因为iText的大部分内容都经过了重组。 我找到的所有关于如何做到这一点的例子和教程都是针对iText5的。(非常好的)白皮书也是如此。它们依赖于通过方法返回的列表,在该方法上执行所有与签名相关的操作。 在iText7中,不再具有该方法。 有人知道iText7的例子/文档吗?
随着WebCrypto API的发展和Chrome和Firefox的支持,我想使用它对PDF文档进行数字签名。这里的文献不多,但我找到了一些例子[1]和一个名为pki.js[2]的库。在示例中,描述了签名过程,但最终返回签名。我希望我的Base64 PDF文件再次返回一个签名的Base64字符串,但不幸的是,这不是发生的事情。据我所知,pki.js也没有提供签署Base64 PDF的方法。 有没有
本文向大家介绍c# 给pdf添加数字签名的步骤,包括了c# 给pdf添加数字签名的步骤的使用技巧和注意事项,需要的朋友参考一下 数字签名广泛用于保护PDF文档,可见数字签名在日常生活中是相当重要的。在这篇文章中我将与大家分享如何给PDF文件添加可见的数字签名。 首先我下载了一个由E-iceblue公司开发的免费版的PDF组件-Free Spire.PDF,控件安装好后,再通过下面所提及的路径把Bi
我必须创建一个PDF文件,其中我使用PDFmake来实现这一点。但PDFmake不具备在文档中添加签名字段的功能。 因此,我打开了一个带有签名字段的示例PDF,并复制了包含签名字段名称的对象:
出身背景 我使用iTextSharp已经有一段时间了。我已经创建了一个带有两个可签名的PdfFormFields的pdf文档。如果我打开pdf文档,我可以手动对每个字段进行手动签名。我希望通过iTextSharp完成这件事。 我目前正在从X509Store检索证书。直到现在,我都能弄明白。 问题 有人能告诉我如何使用X509Certificate2签署一个已经存在的签名字段吗。 工具书类 以下参考