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;
 }
예제 #2
0
 public static CryptoToken createSoftToken(boolean nodefaultpwd, boolean extractable) {
   Properties prop = new Properties();
   if (nodefaultpwd) {
     prop.setProperty(SoftCryptoToken.NODEFAULTPWD, Boolean.toString(nodefaultpwd));
   }
   if (extractable) {
     prop.setProperty(CryptoToken.ALLOW_EXTRACTABLE_PRIVATE_KEY, Boolean.toString(true));
   } else {
     prop.setProperty(CryptoToken.ALLOW_EXTRACTABLE_PRIVATE_KEY, Boolean.toString(false));
   }
   CryptoToken catoken =
       CryptoTokenFactory.createCryptoToken(SoftCryptoToken.class.getName(), prop, null, 111);
   return catoken;
 }