谁能给我一个使用 MSCAPI 和 ITEXT 从 USB 令牌签署 pdf 的简单示例。我不想使用固定的 ocsp 字符串。
我试图遵循这本 数字签名书,但没有奏效。我的代码是:
LoggerFactory.getInstance().setLogger(new SysoLogger());
BouncyCastleProvider providerBC = new BouncyCastleProvider();
Security.addProvider(providerBC);
SunMSCAPI provdierMSCAP = new SunMSCAPI();
Security.addProvider(provdierMSCAP);
KeyStore ks = KeyStore.getInstance("Windows-MY");
ks.load(null, null);
String alias = (String)ks.aliases().nextElement();
PrivateKey pk = (PrivateKey)ks.getKey(alias, null);
Certificate[] chain = ks.getCertificateChain(alias);
PdfReader pdfreader = new PdfReader("HelloWorld.pdf");
FileOutputStream outputFile = new FileOutputStream("Signed.pdf");
PdfStamper pdfstamper;
pdfstamper = PdfStamper.createSignature(pdfreader, outputFile, '\0', null, true);
PdfSignatureAppearance sap = pdfstamper.getSignatureAppearance();
sap.setCrypto(pk, chain, null, PdfSignatureAppearance.SELF_SIGNED);
sap.setReason("Test");
sap.setLocation("Dhaka");
sap.setVisibleSignature(new Rectangle(10, 10, 50, 30), 1, "Test");
pdfstamper.close();
JOptionPane.showMessageDialog(null, "Successfully Signed");
它给了我以下错误:
java.lang.NullPointerException
我尝试使用 itext 5.2.1/itextpdf-5.3.5 和 bcmail-jdk16-1.46、bcprov-jdk16-1.46.jar、bctsp-jdk16-1.46.jar。
任何人都可以帮忙吗?请 ................