JAVA 및 포르투갈어 시민 카드 (스마트 카드) 용 iText를 사용하여 pdf에서 서명을 만들려고합니다.iText 및 디지털 서명
java.security.InvalidKeyException : 공급 키 (sun.security.pkcs11.P11Key $ P11PrivateKey가)
나는 RSAPrivateKey 예를없는 코드 MakeSignature 클래스를 실행할 때하지만 난 항상 말하는 오류가 발생 여기 좀 도와 줘, 아무도 도와 줄 수 없어?
try {
String pkcs11Config = "name=GemPC" + "\n" + "library=C:/WINDOWS/system32/pteidpkcs11.dll";
ByteArrayInputStream configStream = new ByteArrayInputStream(pkcs11Config.getBytes());
Provider pkcs11Provider = new sun.security.pkcs11.SunPKCS11(configStream);
Security.addProvider(pkcs11Provider);
CallbackHandler cmdLineHdlr = new DialogCallbackHandler();
KeyStore.Builder builder = KeyStore.Builder.newInstance("PKCS11", pkcs11Provider,
new KeyStore.CallbackHandlerProtection(cmdLineHdlr));
KeyStore ks = builder.getKeyStore();
PdfReader pdf = new PdfReader(filePath);
FileOutputStream fos = new FileOutputStream(dest);
PdfStamper stp = PdfStamper.createSignature(pdf, fos, '\0');
PdfSignatureAppearance sap = stp.getSignatureAppearance();
sap.setReason("I'm the author");
String alias = (String) ks.aliases().nextElement();
PrivateKey pk = (PrivateKey) ks.getKey("CITIZEN SIGNATURE CERTIFICATE", null);
Certificate chain = ks.getCertificate(alias);
X509Certificate x509 = (X509Certificate) chain;
x509.checkValidity();
ExternalSignature es = new PrivateKeySignature(pk, "SHA-1", "BC");
ExternalDigest digest = new BouncyCastleDigest();
Certificate[] certs = new Certificate[1];
certs[0] = chain;
MakeSignature.signDetached(sap, digest, es, certs, null, null, null, 0, CryptoStandard.CMS);
return dest;
} catch (CertificateExpiredException | CertificateNotYetValidException ex) {
Logger.getLogger(Signer.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
모든 샘플 :
에 대한 :
그래서 아마 당신은 당신의 코드에서 공급자를 변경해야합니다 카드는 null 암호로 만들어집니다. 그리고 iText 5.2에서는 작동하지만 API가 바뀌기 때문에 iText5.5에서는 작동하지 않습니다. 나는 모든 샘플이 그것을 사용하기 때문에 SHA1 해쉬 알고리즘으로 테스트했다. – pedrofernandes
네가 맞아, 나는 너무 빨리 대답했다. 암호는 나중에 PKCS # 11을 사용하여 입력됩니다. –
SHA1은 포르투갈 시민 카드의 표준입니다. 그것은 SHA1 RSA 암호화를 사용합니다. 나는 확인했다. – pedrofernandes