@Test public void testShouldDecryptExternalFile() throws Exception { byte[] plainBytes = Files.readAllBytes(Paths.get(plainFile.getPath())); final String PLAINTEXT = new String(plainBytes, "UTF-8"); InputStream cipherStream = new FileInputStream(unsignedFile); OutputStream recoveredStream = new ByteArrayOutputStream(); String filename = unsignedFile.getName(); OpenPGPKeyBasedEncryptor encryptor = new OpenPGPKeyBasedEncryptor( EncryptionMethod.PGP.getAlgorithm(), EncryptionMethod.PGP.getProvider(), SECRET_KEYRING_PATH, USER_ID, PASSWORD.toCharArray(), filename); StreamCallback decryptionCallback = encryptor.getDecryptionCallback(); decryptionCallback.process(cipherStream, recoveredStream); byte[] recoveredBytes = ((ByteArrayOutputStream) recoveredStream).toByteArray(); String recovered = new String(recoveredBytes, "UTF-8"); logger.info("Recovered: {}", recovered); Assert.assertEquals("Recovered text", PLAINTEXT, recovered); }
@Override public StreamCallback getDecryptionCallback() throws Exception { return new OpenPGPDecryptCallback(provider, keyring, passphrase); }
OpenPGPKeyBasedEncryptor implements Encryptor { @Override public StreamCallback getDecryptionCallback() throws Exception { return new OpenPGPDecryptCallback(provider, keyring, passphrase); } }
OpenPGPKeyBasedEncryptor implements Encryptor { @Override public StreamCallback getDecryptionCallback() throws Exception { return new OpenPGPDecryptCallback(provider, keyring, passphrase); } OpenPGPKeyBasedEncryptor(final String algorithm, final String provider, final String keyring, final String userId, final char[] passphrase, final String filename); }
OpenPGPKeyBasedEncryptor implements Encryptor { @Override public StreamCallback getDecryptionCallback() throws Exception { return new OpenPGPDecryptCallback(provider, keyring, passphrase); } OpenPGPKeyBasedEncryptor(final String algorithm, final String provider, final String keyring, final String userId, final char[] passphrase, final String filename); @Override StreamCallback getEncryptionCallback(); @Override StreamCallback getDecryptionCallback(); static boolean validateKeyring(String provider, String secretKeyringFile, char[] passphrase); @SuppressWarnings("rawtypes") static PGPPublicKey getPublicKey(String userId, String publicKeyringFile); }
OpenPGPKeyBasedEncryptor implements Encryptor { @Override public StreamCallback getDecryptionCallback() throws Exception { return new OpenPGPDecryptCallback(provider, keyring, passphrase); } OpenPGPKeyBasedEncryptor(final String algorithm, final String provider, final String keyring, final String userId, final char[] passphrase, final String filename); @Override StreamCallback getEncryptionCallback(); @Override StreamCallback getDecryptionCallback(); static boolean validateKeyring(String provider, String secretKeyringFile, char[] passphrase); @SuppressWarnings("rawtypes") static PGPPublicKey getPublicKey(String userId, String publicKeyringFile);  }