使用合格证书签名的问题-智能卡PKCS11

时间:2018-12-07 09:30:55

标签: java smartcard xades4j

我对以下代码有疑问。当我尝试签署xml文件时,它崩溃了。 字段PIN固定到智能卡,并且100%正确。我不知道哪里出了问题。有人可以帮助我吗?

    PKCS11KeyStoreKeyingDataProvider ptccKeyingDataProv = new PKCS11KeyStoreKeyingDataProvider(
            "C:\\Windows\\System32\\cryptoCertum3PKCS.dll", "CertumQCA2017",
            new FirstCertificateSelector(), new DirectPasswordProvider(PIN), null, false);
    XadesSigner signer = (XadesSigner) new XadesBesSigningProfile(ptccKeyingDataProv)
            .newSigner();
    new Enveloped(signer).sign(elemToSign);

我在新的Enveloped(signer).sign(elemToSign)行有CKR_FUNCTION_FAILED错误;

完整的堆栈跟踪:

    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:158)
    at xades4j.production.SignerBES.sign(SignerBES.java:129)
    at xades4j.production.Enveloped.sign(Enveloped.java:68)
    at pl.softmedica.ezla.SerwisZLA.zalogujPodpisem(SerwisZLA.java:96)
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)
    ... 91 more
Caused by: java.io.IOException: load failed
    at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:858)
    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)
    ... 92 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:864)
    at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:849)
    ... 97 more
    Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_FUNCTION_FAILED
    at sun.security.pkcs11.wrapper.PKCS11.C_Login(Native Method)
    at sun.security.pkcs11.SunPKCS11.login(SunPKCS11.java:1222)
    ... 99 more

0 个答案:

没有答案