@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(encryptedFile); OutputStream recoveredStream = new ByteArrayOutputStream(); String filename = encryptedFile.getName(); OpenPGPPasswordBasedEncryptor encryptor = new OpenPGPPasswordBasedEncryptor(EncryptionMethod.PGP.getAlgorithm(), EncryptionMethod.PGP.getProvider(), LEGACY_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, password); }
OpenPGPPasswordBasedEncryptor implements Encryptor { @Override public StreamCallback getDecryptionCallback() throws Exception { return new OpenPGPDecryptCallback(provider, password); } }
OpenPGPPasswordBasedEncryptor implements Encryptor { @Override public StreamCallback getDecryptionCallback() throws Exception { return new OpenPGPDecryptCallback(provider, password); } OpenPGPPasswordBasedEncryptor(final String algorithm, final String provider, final char[] passphrase, final String filename); }
OpenPGPPasswordBasedEncryptor implements Encryptor { @Override public StreamCallback getDecryptionCallback() throws Exception { return new OpenPGPDecryptCallback(provider, password); } OpenPGPPasswordBasedEncryptor(final String algorithm, final String provider, final char[] passphrase, final String filename); @Override StreamCallback getEncryptionCallback(); @Override StreamCallback getDecryptionCallback(); }
OpenPGPPasswordBasedEncryptor implements Encryptor { @Override public StreamCallback getDecryptionCallback() throws Exception { return new OpenPGPDecryptCallback(provider, password); } OpenPGPPasswordBasedEncryptor(final String algorithm, final String provider, final char[] passphrase, final String filename); @Override StreamCallback getEncryptionCallback(); @Override StreamCallback getDecryptionCallback();  }