public static boolean isEncryptedFile(Path file) { try (FileInputStream input = new FileInputStream(file.toFile())) { PGPObjectFactory factory = new PGPObjectFactory(input, FP_CALC); Object o = factory.nextObject(); return o instanceof PGPEncryptedDataList || o instanceof PGPMarker; // NOTE: exception class is not well defined for non-pgp data } catch(IOException | RuntimeException ex) { return false; } }