JkGpg { public Path sign(Path fileToSign, String keyname) { final Path signatureFile = getSignatureFile(fileToSign); sign(fileToSign, keyname, signatureFile); return signatureFile; } private  JkGpg(Path pubRing, Path secRing, String password); static JkGpg of(Path pubRing, Path secRing, String password); static Path getDefaultPubring(); static Path getDefaultSecring(); static JkGpg ofDefaultGnuPg(); static JkGpg ofPublicRing(Path pubRing); static JkGpg ofSecretRing(Path secRing, String password); Path sign(Path fileToSign, String keyname); void sign(Path fileToSign, String keyName, Path signatureFile); static Path getSignatureFile(Path fileToSign); boolean verify(Path fileToVerify, Path signature); JkGpg withSecretRing(Path file, String password); JkGpg withPublicRing(Path file); JkGpg withSecretRingPassword(String pwd); Path getSecretRing(); Path getPublicRing(); UnaryOperator<Path> getSigner(String keyName);  }
@Test public void testSign() throws Exception { final Path pubFile = Paths.get(JkGpgTest.class.getResource("pubring.gpg").toURI()); final Path secringFile = Paths.get(JkGpgTest.class.getResource("secring.gpg").toURI()); final JkGpg pgp = JkGpg.of(pubFile, secringFile, "jerkar"); final Path signatureFile = Paths.get(JkConstants.OUTPUT_PATH+ "/test-out/signature.asm"); if (!Files.exists(signatureFile)) { Files.createDirectories(signatureFile.getParent()); Files.createFile(signatureFile); } final Path sampleFile = Paths.get(JkGpgTest.class.getResource("sampleFileToSign.txt").toURI()); Path signature = pgp.sign(sampleFile, ""); System.out.println("Signature file : " + signature); }