signandverify.java
来自「Java生成PDF Java生成PDF Java生成PDF」· Java 代码 · 共 43 行
JAVA
43 行
import org.faceless.pdf2.*;import java.io.*;import java.security.GeneralSecurityException;/** * This class creates an empty PDF, signs it with our DummyHandler and * then verifies it. Try tweaking the PDF file slightly between the sign * and verify stage - you'll find that the signature no longer verifies. */public class SignAndVerify{ public static void main(String[] args) throws IOException, GeneralSecurityException { sign(); verify(); } private static void sign() throws IOException, GeneralSecurityException { PDF pdf = new PDF(); PDFPage page = pdf.newPage(PDF.PAGESIZE_A4); Form form = pdf.getForm(); SignatureHandlerFactory factory = new DummySignatureHandlerFactory(); FormSignature sig = new FormSignature(null, null, null, factory); form.getElements().put("DummySig", sig); pdf.render(new FileOutputStream("Signed.pdf")); } private static void verify() throws IOException, GeneralSecurityException { PDF pdf = new PDF(new PDFReader(new File("Signed.pdf"))); FormSignature.registerHandlerForVerification(new DummySignatureHandlerFactory()); FormSignature sig = (FormSignature)pdf.getForm().getElement("DummySig"); System.out.println("Verified = "+sig.verify()); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?