class SecretKeyInput extends BaseImportInput {

    @Override
    public ByteArrayInputStream getFileInputStream(String path) throws IOException {
        if (secretKey != null && secretKey.length > 0) {
            try {
                final byte[] key = Hexer.parse(secretKey);
                return new ByteArrayInputStream(key);
            } catch (Exception e) {
                throw new IOException(format("Key import failed due to error: can't parse hex \"%s\"",
                        String.join(" ", secretKey)), e);
            }

        } else if (parameters.hasGenKey()) {
            return new ByteArrayInputStream(new byte[0]);

        } else {
            Optional<String> keyStoreParam = parameters.getKeyStore();
            final KeyStore keystore;

            if (keyStoreParam.isPresent() && !keyStoreParam.get().isEmpty()) {
                String keyStorePasswd = parameters.getKeyStorePasswd().orElse("");

                final Enumeration<String> aliases;
                try(InputStream keyStoreFile = new FileInputStream(keyStoreParam.get())) {
                    keystore = KeyStore.getInstance(parameters.getKeyStoreType().orElse(KeystoreManager.KS_TYPE));
                    keystore.load(keyStoreFile, keyStorePasswd.toCharArray());
                    aliases = keystore.aliases();
                } catch (KeyStoreException | CertificateException | NoSuchAlgorithmException e) {
                    throw new IOException("Failed to load provided keystore", e);
                }

                if(!aliases.hasMoreElements()){
                    throw new IOException("Failed to import a key. Keystore is empty.");
                }

                final String firstAlias = aliases.nextElement();

                final String keyAlias;
                String keyPasswd;
                if (parameters.getKeyAlias().isPresent()) {
                    keyAlias = parameters.getKeyAlias().get();
                    keyPasswd = parameters.getKeyPasswd().orElseThrow(() -> new RuntimeException("Key password was not specified"));
                } else {
                    keyAlias = firstAlias;
                    parameters.setKeyAlias(keyAlias);
                    keyPasswd = keyStorePasswd;
                    parameters.setKeyPasswd(keyStorePasswd);
                }

                try {
                    Key key = keystore.getKey(keyAlias, keyPasswd.toCharArray());
                    if (!parameters.getKeyAlg().isPresent()) {
                        parameters.setKeyAlg(key.getAlgorithm());
                    } else {
                        if (!key.getAlgorithm().equalsIgnoreCase(parameters.getKeyAlg().get())) {
                           throw new RuntimeException("ERROR: Specified key algorithm doesn't match the recovered key algorithm from the keystore.");
                        }
                    }

                    return new ByteArrayInputStream(key.getEncoded());
                } catch (KeyStoreException | NoSuchAlgorithmException | UnrecoverableKeyException e) {
                    throw new IOException("Failed to import specified key", e);
                }
            }
        }

        throw new IOException("No key or keystore was specified.");
    }

    public  SecretKeyInput(String[] secretKey, EncryptionParams parameters);

}