private static PKCS8EncodedKeySpec createEncryptedKeySpec(byte[] keyBytes, char[] password) throws IOException {
      EncryptedPrivateKeyInfo encrypted = new EncryptedPrivateKeyInfo(keyBytes);
      PBEKeySpec encryptedKeySpec = new PBEKeySpec(password);
      try {
        SecretKeyFactory pbeKeyFactory = SecretKeyFactory.getInstance(encrypted.getAlgName());
        return encrypted.getKeySpec(pbeKeyFactory.generateSecret(encryptedKeySpec));
      }
      catch (GeneralSecurityException e) {
        throw new IOException("JCE error: " + e.getMessage(), e);
      }
    }
private static PKCS8EncodedKeySpec createEncryptedKeySpec(byte[] keyBytes, char[] password)