Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is ASCII armoring supported? #24

Closed
mgrossmann opened this issue Nov 13, 2018 · 1 comment
Closed

Is ASCII armoring supported? #24

mgrossmann opened this issue Nov 13, 2018 · 1 comment
Labels

Comments

@mgrossmann
Copy link

mgrossmann commented Nov 13, 2018

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
Copy link
Owner

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));
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants