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 org.mule.util.IOUtils;
10  
11  import java.io.FileInputStream;
12  import java.net.URL;
13  
14  import org.junit.Test;
15  
16  import static org.junit.Assert.assertEquals;
17  import static org.junit.Assert.assertNotNull;
18  
19  public class KeyBasedEncryptionStrategyTestCase extends AbstractEncryptionStrategyTestCase
20  {
21  
22      @Test
23      public void testDecrypt() throws Exception
24      {
25          URL url = Thread.currentThread().getContextClassLoader().getResource("./encrypted-signed.asc");
26  
27          FileInputStream in = new FileInputStream(url.getFile());
28          byte[] msg = IOUtils.toByteArray(in);
29          in.close();
30  
31          PGPCryptInfo cryptInfo = new PGPCryptInfo(kbStrategy.getKeyManager().getPublicKey(
32              "Mule client <mule_client@mule.com>"), true);
33  
34          String result = new String(kbStrategy.decrypt(msg, cryptInfo));
35          assertEquals("This is a test message.\r\nThis is another line.\r\n", result);
36      }
37  
38      @Test
39      public void testEncrypt() throws Exception
40      {
41          String msg = "Test Message";
42          PGPCryptInfo cryptInfo = new PGPCryptInfo(kbStrategy.getKeyManager().getPublicKey(
43              "Mule client <mule_client@mule.com>"), true);
44  
45          String result = new String(kbStrategy.encrypt(msg.getBytes(), cryptInfo));
46          assertNotNull(result);
47      }
48  }