gpt4 book ai didi

java - 用合格证书签署文件-智能卡

转载 作者:行者123 更新时间:2023-12-02 03:04:20 27 4
gpt4 key购买 nike

下面的代码适用于 2 个不同的加密智能卡库(certum cryptoCertum3PKCS.dll 和 cencert enigmap11.dll ),但在提供用于 100%正确

有人知道我做错了什么吗?

  KeyingDataProvider kp = new PKCS11KeyStoreKeyingDataProvider(
settings.getDriverPath(),
settings.getProviderName(),
settings.getSlot(),
new CertificateSelector(),
new KeyStorePasswordProvider(), null, false);

Document src = getDocumentBuilder().parse(new File(filename));
Document dest = getDocumentBuilder().newDocument();
Node objContent = dest.importNode(src.getDocumentElement(), true);

XadesSigner signer = new XadesBesSigningProfile(kp).newSigner();

DataObjectDesc obj = new EnvelopedXmlObject(objContent, "text/xml", null);
signer.sign(new SignedDataObjects(obj), dest);

Transformer transformer = TransformerFactory.newInstance().newTransformer();
Result output = new StreamResult(new File(signed));
Source input = new DOMSource(dest);

transformer.transform(input, output);

我在行signer.sign(new SignedDataObjects(obj), dest);处出现CKR_PIN_LEN_RANGE错误完整的堆栈跟踪:

 xades4j.verification.UnexpectedJCAException: The keystore couldn't be initialized
at xades4j.providers.impl.KeyStoreKeyingDataProvider.ensureInitialized(KeyStoreKeyingDataProvider.java:179)
at xades4j.providers.impl.KeyStoreKeyingDataProvider.getSigningCertificateChain(KeyStoreKeyingDataProvider.java:189)
at xades4j.production.SignerBES.sign(SignerBES.java:151)
at xades4j.production.SignerBES.sign(SignerBES.java:122)
at com.riv.jpk.security.XadesHelper.sign(XadesHelper.java:127)
at com.riv.jpk.RaportGenerators.BaseGen.signXml(BaseGen.java:192)
at com.riv.jpk.ui.views.GenerateJPK.JpkGeneratorVM.signXml(JpkGeneratorVM.java:417)
at com.riv.jpk.ui.views.GenerateJPK.JpkGeneratorVM.lambda$validateMetaXML$44(JpkGeneratorVM.java:403)
at com.riv.jpk.ui.views.GenerateJPK.JpkGeneratorVM$$Lambda$361/32216595.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.concurrent.EventHelper.fireEvent(EventHelper.java:219)
at javafx.concurrent.Task.fireEvent(Task.java:1356)
at javafx.concurrent.Task.setState(Task.java:723)
at javafx.concurrent.Task$TaskCallable.lambda$call$496(Task.java:1434)
at javafx.concurrent.Task$TaskCallable$$Lambda$347/3131345.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$51/6271097.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
at com.sun.javafx.application.PlatformImpl$$Lambda$49/19468568.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$39/443957.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745) Caused by: java.security.KeyStoreException: KeyStore instantiation failed
at java.security.KeyStore$Builder$2.getKeyStore(KeyStore.java:1967)
at xades4j.providers.impl.KeyStoreKeyingDataProvider.ensureInitialized(KeyStoreKeyingDataProvider.java:175)
... 32 more
Caused by: java.io.IOException: load failed
at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:843)
at java.security.KeyStore.load(KeyStore.java:1479)
at java.security.KeyStore$Builder$2$1.run(KeyStore.java:1937)
at java.security.KeyStore$Builder$2$1.run(KeyStore.java:1918)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.KeyStore$Builder$2.getKeyStore(KeyStore.java:1964)
... 33 more
Caused by: javax.security.auth.login.LoginException
at sun.security.pkcs11.SunPKCS11.login(SunPKCS11.java:1238)
at sun.security.pkcs11.P11KeyStore.login(P11KeyStore.java:849)
at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:834)
... 38 more
Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_PIN_LEN_RANGE
at sun.security.pkcs11.wrapper.PKCS11.C_Login(Native Method)
at sun.security.pkcs11.SunPKCS11.login(SunPKCS11.java:1222)
... 40 more

最佳答案

我找到了!解决方案是在创建 KeyingDataProvider 之前运行 C_GetSlotList。

PKCS11 p11 = PKCS11.getInstance(settings.getDriverPath(), "C_GetFunctionList", null, false);
long[] slots = p11.C_GetSlotList(true);

我不确定到底是怎么回事。在此智能卡中,合格证书位于插槽 3 上,并且看起来 java pksc#11 实现在运行 C_GetSlotList 之前获取此插槽时存在问题。

关于java - 用合格证书签署文件-智能卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41958819/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com