View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.pgp;
8   
9   import java.io.IOException;
10  import java.io.InputStream;
11  
12  import org.apache.commons.io.IOUtils;
13  import org.bouncycastle.openpgp.PGPPublicKey;
14  import org.bouncycastle.openpgp.PGPSecretKey;
15  
16  public class SignedMessage implements Message
17  {
18  
19      private LazyTransformedInputStream encryptedMessage;
20  
21      public SignedMessage(InputStream toBeDecrypted,
22                           PGPPublicKey publicKey,
23                           PGPSecretKey secretKey,
24                           String password) throws IOException
25      {
26          StreamTransformer transformer = new DecryptStreamTransformer(toBeDecrypted, publicKey, secretKey,
27              password);
28          this.encryptedMessage = new LazyTransformedInputStream(new TransformContinuouslyPolicy(), transformer);
29      }
30  
31      public boolean verify()
32      {
33          // TODO Signed messages is not implemented yet
34          return false;
35      }
36  
37      public Message getContents() throws IOException
38      {
39          String contents = IOUtils.toString(this.encryptedMessage);
40          return new LiteralMessage(contents.getBytes());
41      }
42  
43  }