@Override
    public JavaKeyStore create(SecureConfig config) {
        if (exists(config)) {
            throw new SecretStoreException.AlreadyExistsException(String.format("Logstash keystore at %s already exists.",
                    new String(config.getPlainText(PATH_KEY))));
        }
        try {
            init(config);
            lock.lock();
            LOGGER.debug("Creating new keystore at {}.", keyStorePath.toAbsolutePath());
            String keyStorePermissions = filePermissions;
            //create the keystore on disk with a default entry to identify this as a logstash keystore
            //can not set posix attributes on create here since not all Windows are posix, *nix will get the umask default and posix permissions will be set below
            Files.createFile(keyStorePath);
            try {
                keyStore = KeyStore.Builder.newInstance(KEYSTORE_TYPE, null, protectionParameter).getKeyStore();
                SecretKeyFactory factory = SecretKeyFactory.getInstance("PBE");
                byte[] base64 = SecretStoreUtil.base64Encode(LOGSTASH_MARKER.getKey().getBytes(StandardCharsets.UTF_8));
                SecretKey secretKey = factory.generateSecret(new PBEKeySpec(SecretStoreUtil.asciiBytesToChar(base64)));
                keyStore.setEntry(LOGSTASH_MARKER.toExternalForm(), new KeyStore.SecretKeyEntry(secretKey), protectionParameter);
                saveKeyStore();
                PosixFileAttributeView attrs = Files.getFileAttributeView(keyStorePath, PosixFileAttributeView.class);
                if (attrs != null) {
                    //the directory umask applies when creating the file, so re-apply permissions here
                    attrs.setPermissions(PosixFilePermissions.fromString(keyStorePermissions));
                }
                LOGGER.info("Created Logstash keystore at {}", keyStorePath.toAbsolutePath());
                return this;
            } catch (Exception e) {
                throw new SecretStoreException.CreateException("Failed to create Logstash keystore.", e);
            }
        } catch (SecretStoreException sse) {
            throw sse;
        } catch (NoSuchFileException | AccessDeniedException fe) {
            throw new SecretStoreException.CreateException("Error while trying to create the Logstash keystore. Please ensure that path to " + keyStorePath.toAbsolutePath() +
                    " exists and is writable", fe);
        } catch (Exception e) { //should never happen
            throw new SecretStoreException.UnknownException("Error while trying to create the Logstash keystore. ", e);
        } finally {
            releaseLock(lock);
            config.clearValues();
        }
    }
@Test
    public void testEmptyNotAllowedOnCreate() throws IOException {
        Path altPath = folder.newFolder().toPath().resolve("alt.logstash.keystore");
        SecureConfig altConfig = new SecureConfig();
        altConfig.add("keystore.file", altPath.toString().toCharArray());
        altConfig.add(SecretStoreFactory.KEYSTORE_ACCESS_KEY, "".toCharArray());

        assertThrows(SecretStoreException.CreateException.class, () -> {
            new JavaKeyStore().create(altConfig);
        });
    }