Is ASCII armoring supported?
Closed this issue · 1 comments
mgrossmann commented
Hi there,
first of all many thanks for implementing my change suggestion from pull request #6. Today I would like to ask if decrypting ASCII armored data is already supported.
Greetings Mike
neuhalje commented
Hi @mgrossmann, sure, e.g. in DecryptionStreamFactoryTest.java 48-68 and 296-395 you can see it is supported transparently:
// from ExampleMessages.java
public final static String IMPORTANT_QUOTE_SIGNED_COMPRESSED = "-----BEGIN PGP MESSAGE-----\n" +
"Version: GnuPG v1\n" +
"\n" +
"hQEMA1Sj2zdPeHq3AQf8CPN1Fbg0HXQHSFzONYZyxkabSAMgIzXf/VOp+FWER0A1\n" +
"o9RCajzYwbcSZCLpg9T+xbCJ3nS+ndFs0cx7MSevBSk1tVriiv/Vn0Odj17keX+a\n" +
"YlRkfk1n10JWKrJwS3BJx6JuK8uRmZwpqr+IqFlMu0TJH7rNAfGwbSFgJrHUd4Je\n" +
"ieA8eTXkjnassNTvMlaZVmVi//BjpzK9o91r0zWvp66k6v2uZML0SQT3E6xDTWBM\n" +
"WtHuJqdaAziShn27w9M26zOO9UEpVhjz8fDQAetdMEp1z6p6BL/2p3jayOMeIIcq\n" +
"iCTB0dRgqakBHnY/izzsCXYr3xigchi+gXBAjvzoM9LA+wFSRA3v+jJu6NK2ackD\n" +
"W4gFPNuhI1IoIt9cjP9hZS7rb1stHrQ0QFMwTM/2djRJSw6jjhi7zSnPL61FOdtY\n" +
"NaxNPUv+Ab+QvmM/0notYfNQZIdpaDpJ6jOuXe2qJ2xH4oAGOqqscTO9jB2p6ykQ\n" +
"JtRq4BCcfMk8RddScpZzSK9JA1jslzpXbYAFWqvMVDSYwHGSP8FgAJUMbI7ZdNGt\n" +
"nRXDxDhBdfR7ix1NcYwg+g1f7qf3j2cgYhgMVajSqGSW84HfUOcNVSQz9M+GrWtS\n" +
"nwzrqU3ar1qg5TcaPc2NE8b5SGh/3afG+kpkVufUqPPgAtfSMxgB9d9fqdqtO8zp\n" +
"jqC6lrR63jXiH1CovCUPJ65jJou6EZ+vbjx9ISxMqYuqBSuafxvPsAhb2fu5NsJW\n" +
"Y4BCBhe3gFr40bhlnK7P1+ot3XYLm01GTTI1CmDLlQIH2aSozhsRE/ahc/1xf75U\n" +
"jidHHK5iPFfBAo2ouCmb6HRhPUOzMHuMHCMRqScOSI/Css6BvLaqoHCUBwzN8Dhb\n" +
"kfkE8g9Jm9QfsIaCwfcTqJslO22BSIANmm2Ho8vevPzS0uTxnugoRaA6r0qw\n" +
"=dQ4L\n" +
"-----END PGP MESSAGE-----";
// DecryptionStreamFactoryTest.java
private String decrypt(byte[] encrypted, KeyringConfig config,
SignatureValidationStrategy signatureValidationStrategy) throws IOException {
final DecryptionStreamFactory sut = DecryptionStreamFactory
.create(config, signatureValidationStrategy);
final InputStream plainTextInputStream;
try {
plainTextInputStream = sut.wrapWithDecryptAndVerify(new ByteArrayInputStream(encrypted));
} catch (NoSuchProviderException e) {
assertTrue("BC provider must be registered by test", false);
throw new AssertionError(e);
}
ByteArrayOutputStream res = new ByteArrayOutputStream();
Streams.pipeAll(plainTextInputStream, res);
res.close();
plainTextInputStream.close();
String decrypted = res.toString("US-ASCII");
return decrypted;
}
// ..
@Test
public void decryptingSignedMessageWithSingleeSignatures_andAnySignatureIsRequired_succeeds()
throws IOException, SignatureException {
final KeyringConfig config = Configs.keyringConfigFromFilesForRecipient();
//
final String decryptedQuote = decrypt(IMPORTANT_QUOTE_SIGNED_COMPRESSED.getBytes("US-ASCII"),
config, SignatureValidationStrategies.requireAnySignature());
Assert.assertThat(decryptedQuote, equalTo(IMPORTANT_QUOTE_TEXT));
}