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.mule.security;
8   
9   import org.mule.security.PasswordBasedEncryptionStrategy;
10  import org.mule.tck.junit4.AbstractMuleTestCase;
11  
12  import org.junit.Test;
13  
14  import static org.junit.Assert.assertEquals;
15  import static org.junit.Assert.assertNotSame;
16  
17  public class PbeEncryptionStrategyTestCase extends AbstractMuleTestCase
18  {
19  
20      @Test
21      public void testRoundTripEncryption() throws Exception
22      {
23          PasswordBasedEncryptionStrategy pbe = new PasswordBasedEncryptionStrategy();
24          pbe.setPassword("test");
25          pbe.initialise();
26  
27          byte[] b = pbe.encrypt("hello".getBytes(), null);
28  
29          assertNotSame(new String(b), "hello");
30          String s = new String(pbe.decrypt(b, null), "UTF-8");
31          assertEquals("hello", s);
32      }
33  }