View Javadoc

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