class CertUtils {

  private CertUtils() {
  }

  public static InputStream getInputStreamFromDataOrFile(String data, String file) throws FileNotFoundException {<FILL_FUNCTION_BODY>}

  public static KeyStore createKeyStore(InputStream certInputStream, InputStream keyInputStream, String clientKeyAlgo,
      char[] clientKeyPassphrase)
      throws IOException, CertificateException, NoSuchAlgorithmException, InvalidKeySpecException, KeyStoreException {
    CertificateFactory certFactory = CertificateFactory.getInstance("X509");
    X509Certificate cert = (X509Certificate) certFactory.generateCertificate(certInputStream);

    byte[] keyBytes = decodeKey(keyInputStream);

    PrivateKey privateKey;

    KeyFactory keyFactory = KeyFactory.getInstance(clientKeyAlgo);
    try {
      // First let's try PKCS8
      privateKey = keyFactory.generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
    } catch (InvalidKeySpecException e) {
      // Otherwise try PKCS8
      RSAPrivateCrtKeySpec keySpec = PKCS1Util.decodePKCS1(keyBytes);
      privateKey = keyFactory.generatePrivate(keySpec);
    }

    KeyStore keyStore = KeyStore.getInstance("JKS");
    keyStore.load(null, clientKeyPassphrase);

    String alias = cert.getSubjectX500Principal().getName();
    keyStore.setKeyEntry(alias, privateKey, clientKeyPassphrase, new Certificate[] { cert });

    return keyStore;
  }

  public static KeyStore createKeyStore(String clientCertData, String clientCertFile, String clientKeyData,
      String clientKeyFile, String clientKeyAlgo, char[] clientKeyPassphrase)
      throws IOException, CertificateException, NoSuchAlgorithmException, InvalidKeySpecException, KeyStoreException {
    try (InputStream certInputStream = getInputStreamFromDataOrFile(clientCertData, clientCertFile);
        InputStream keyInputStream = getInputStreamFromDataOrFile(clientKeyData, clientKeyFile)) {
      return createKeyStore(certInputStream, keyInputStream, clientKeyAlgo, clientKeyPassphrase);
    }
  }

  private static byte[] decodeKey(InputStream keyInputStream) throws IOException {
    try (BufferedReader keyReader = new BufferedReader(new InputStreamReader(keyInputStream));
        ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
      String line;
      while ((line = keyReader.readLine()) != null) {
        baos.write(line.trim().getBytes());
      }
      return Base64.getDecoder().decode(baos.toByteArray());
    }
  }
}

    if (data != null) {
      final byte[] bytes;
      ByteString decoded = ByteString.decodeBase64(data);
      if (decoded != null) {
        bytes = decoded.toByteArray();
      } else {
        bytes = data.getBytes();
      }

      return new ByteArrayInputStream(bytes);
    }
    if (file != null) {
      return new FileInputStream(file);
    }
    return null;
  
<no_super_class>