public static CryptoToken createPKCS11TokenWithAttributesFile( String file, String tokenName, boolean extractable) throws NoSuchSlotException { Properties prop = new Properties(); String hsmlib = PKCS11TestUtils.getHSMLibrary(); assertNotNull(hsmlib); prop.setProperty(PKCS11CryptoToken.SHLIB_LABEL_KEY, hsmlib); prop.setProperty(PKCS11CryptoToken.SLOT_LABEL_VALUE, PKCS11TestUtils.getPkcs11SlotValue("1")); prop.setProperty( PKCS11CryptoToken.SLOT_LABEL_TYPE, PKCS11TestUtils.getPkcs11SlotType(Pkcs11SlotLabelType.SLOT_NUMBER.getKey()).getKey()); if (file != null) { prop.setProperty(PKCS11CryptoToken.ATTRIB_LABEL_KEY, file); } if (tokenName != null) { prop.setProperty(PKCS11CryptoToken.TOKEN_FRIENDLY_NAME, tokenName); } if (extractable) { prop.setProperty(CryptoToken.ALLOW_EXTRACTABLE_PRIVATE_KEY, "True"); } else { prop.setProperty(CryptoToken.ALLOW_EXTRACTABLE_PRIVATE_KEY, "False"); } CryptoToken catoken = CryptoTokenFactory.createCryptoToken( PKCS11CryptoToken.class.getName(), prop, null, 111, "P11 CryptoToken"); return catoken; }
@Override String getProvider() { return PKCS11TestUtils.getHSMProvider(); }