PKCS11Exception:CKR_TOKEN_NOT_RECOGNIZED

时间:2017-04-10 07:21:07

标签: java pkcs#11 hsm softhsm

我安装了Softhsm v 2.2并开始使用

上的PkCS#11 Java API

操作:

  1. 1.Slot Creation
    1. 令牌创建
    2. 密钥生成
    3. 加密
    4. 登录
    5. 密钥检索
  2. 我得到以下异常:

        Exception in thread "main" java.security.ProviderException: Initialization failed
            at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:376)
            at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:103)
            at SoftHSM.main(SoftHSM.java:47)
        Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_TOKEN_NOT_RECOGNIZED
            at sun.security.pkcs11.wrapper.PKCS11.C_OpenSession(Native Method)
            at sun.security.pkcs11.SessionManager.openSession(SessionManager.java:215)
            at sun.security.pkcs11.SessionManager.getOpSession(SessionManager.java:150)
            at sun.security.pkcs11.Token.<init>(Token.java:151)
            at sun.security.pkcs11.SunPKCS11.initToken(SunPKCS11.java:858)
            at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:367)
            ... 2 more
    

    我的softhsm.cfg

        name = SoftHSM
        library = Z:\SOFTHSM_INSTALL\lib\softhsm2-x64.dll
    
        slot= 0
    
        attributes(generate, *, *) = {
           CKA_TOKEN = true
        }
        attributes(generate, CKO_CERTIFICATE, *) = {
           CKA_PRIVATE = false
        }
        attributes(generate, CKO_PUBLIC_KEY, *) = {
           CKA_PRIVATE = false
        }
    

    重新启动PC后我尝试了另一个:

        C:\SoftHSM2\bin>softhsm2-util.exe --show-slots
        Available slots:
        Slot 0
            Slot info:
                Description:      SoftHSM slot ID 0x0
                Manufacturer ID:  SoftHSM project
                Hardware version: 2.2
                Firmware version: 2.2
                Token present:    yes
            Token info:
                Manufacturer ID:  SoftHSM project
                Model:            SoftHSM v2
                Hardware version: 2.2
                Firmware version: 2.2
                Serial number:
                Initialized:      no
                User PIN init.:   no
                Label:
    
        C:\SoftHSM2\bin> softhsm2-util.exe --init-token --slot 1 --label "A token"
        === SO PIN (4-255 characters) ===
        Please enter SO PIN: ******
        Please reenter SO PIN: ******
        === User PIN (4-255 characters) ===
        Please enter user PIN: ****
        Please reenter user PIN: ****
        CKR_SLOT_ID_INVALID: Slot 1 does not exist.
    
        C:\SoftHSM2\bin> softhsm2-util.exe --init-token --slot 0 --label "0 token"
        === SO PIN (4-255 characters) ===
        Please enter SO PIN: ******
        Please reenter SO PIN: ******
        === User PIN (4-255 characters) ===
        Please enter user PIN: ****
        Please reenter user PIN: ****
        The token has been initialized.
    
        C:\SoftHSM2\bin>softhsm2-util.exe --show-slots
        Available slots:
        Slot 1526831955
            Slot info:
                Description:      SoftHSM slot ID 0x5b019b53
                Manufacturer ID:  SoftHSM project
                Hardware version: 2.2
                Firmware version: 2.2
                Token present:    yes
            Token info:
                Manufacturer ID:  SoftHSM project
                Model:            SoftHSM v2
                Hardware version: 2.2
                Firmware version: 2.2
                Serial number:    cafa9efc5b019b53
                Initialized:      yes
                User PIN init.:   yes
                Label:            0 token
        Slot 1
            Slot info:
                Description:      SoftHSM slot ID 0x1
                Manufacturer ID:  SoftHSM project
                Hardware version: 2.2
                Firmware version: 2.2
                Token present:    yes
            Token info:
                Manufacturer ID:  SoftHSM project
                Model:            SoftHSM v2
                Hardware version: 2.2
                Firmware version: 2.2
                Serial number:
                Initialized:      no
                User PIN init.:   no
                Label:
    
        C:\SoftHSM2\bin> softhsm2-util.exe --init-token --slot 0 --label "B token"
        === SO PIN (4-255 characters) ===
        Please enter SO PIN: ******
        Please reenter SO PIN: ******
        === User PIN (4-255 characters) ===
        Please enter user PIN: ****
        Please reenter user PIN: ****
        CKR_SLOT_ID_INVALID: Slot 0 does not exist.
    
        C:\SoftHSM2\bin> softhsm2-util.exe --init-token --slot 5 --label "s5 token"
        === SO PIN (4-255 characters) ===
        Please enter SO PIN: ******
        Please reenter SO PIN: ******
        === User PIN (4-255 characters) ===
        Please enter user PIN: ****
        Please reenter user PIN: ****
        CKR_SLOT_ID_INVALID: Slot 5 does not exist.
    
        C:\SoftHSM2\bin> softhsm2-util.exe --init-token --slot 0 --label "1 token"
        === SO PIN (4-255 characters) ===
        Please enter SO PIN: ******
        Please reenter SO PIN: ******
        === User PIN (4-255 characters) ===
        Please enter user PIN: ****
        Please reenter user PIN: ****
        CKR_SLOT_ID_INVALID: Slot 0 does not exist.
    
        C:\SoftHSM2\bin>
    

    但现在它说它已初始化,但我仍然不知道我必须提供什么插槽ID。我尝试使用slot = 1,slot = 1526831955但是我正在

      sun.security.pkcs11.wrapper.PKCS11Exception: CKR_SLOT_ID_INVALID
    

0 个答案:

没有答案