static byte[] readPrivateKey(Path path) throws KeyException {
        final byte[] bytes;
        try {
            bytes = Files.readAllBytes(path);
        } catch (IOException e) {
            throw new KeyException("Couldn't read private key from file: " + path, e);
        }

        final String content = new String(bytes, StandardCharsets.US_ASCII);
        final Matcher m = KEY_PATTERN.matcher(content);
        if (!m.find()) {
            throw new KeyException("No private key found in file: " + path);
        }

        final String s = CharMatcher.breakingWhitespace().removeFrom(m.group(1));
        byte[] base64 = s.getBytes(StandardCharsets.US_ASCII);
        return Base64.getDecoder().decode(base64);
    }
@Test(expected = KeyException.class)
    public void readPrivateKeyFailsOnDirectory() throws Exception {
        final File folder = temporaryFolder.newFolder();
        PemReader.readPrivateKey(folder.toPath());
    }