Register /
Login
|
Desktop view
|
com.pheox.jcapi.JCAPIJNIRuntimeException: Exception raised in JCAPI.DLL:
JCAPISignature_sign() - Could not acquire a key container handle.
at com.pheox.jcapi.CoreSignatureJNI.sign(Native Method)
at com.pheox.jcapi.h.b(Unknown Source)
at com.pheox.jcapi.l.engineSign(Unknown Source)
at java.security.Signature$Delegate.engineSign(Unknown Source)
at java.security.Signature.sign(Unknown Source)
at com.lowagie.text.pdf.PdfPKCS7.getEncodedPKCS7(Unknown Source)
at com.lowagie.text.pdf.PdfPKCS7.getEncodedPKCS7(Unknown Source)
at com.lowagie.text.pdf.PdfSigGenericPKCS.setSignInfo(Unknown Source)
at com.lowagie.text.pdf.PdfSignatureAppearance.preClose(Unknown Source)
at com.lowagie.text.pdf.PdfSignatureAppearance.preClose(Unknown Source)
at com.lowagie.text.pdf.PdfStamper.close(Unknown Source)
at es.com.mipaquete.appletFirma.AppletFirmaJCAPI.signDoc(AppletFirmaJCAPI.java:217)
at es.com.mipaquete.appletFirma.AppletFirmaJCAPI.firmar(AppletFirmaJCAPI.java:192)
at es.com.mipaquete.appletFirma.AppletFirmaJCAPI.firmarDocumentos(AppletFirmaJCAPI.java:161)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.javascript.invoke.JSInvoke.invoke(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
at sun.plugin.com.MethodDispatcher.invoke(Unknown Source)
at sun.plugin.com.DispatchImpl.invokeImpl(Unknown Source)
at sun.plugin.com.DispatchImpl$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.com.DispatchImpl.invoke(Unknown Source)
private String signDoc(String doc, String razon, String lugar) throws Exception
{
byte[] bytes = doc.getBytes();
byte[] decoded = Base64Util.decode(bytes);
PrivateKey key = (PrivateKey)ks.getKey(aliasSeleccionado, null);
Certificate[] chain = ks.getCertificateChain(aliasSeleccionado);
PdfReader reader = new PdfReader(decoded);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfStamper stp = PdfStamper.createSignature(reader, baos, '\0');
PdfSignatureAppearance sap = stp.getSignatureAppearance();
sap.setCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED);
sap.setReason(razon);
sap.setLocation(lugar);
stp.close();
byte[] signedBytes = Base64Util.encode(baos.toByteArray());
String res = new String(signedBytes);
return res;
}