1   /*
2    * $Id: SecretKeyEncryptionStrategyTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.mule.security;
12  
13  import org.mule.impl.security.SecretKeyEncryptionStrategy;
14  import org.mule.tck.AbstractMuleTestCase;
15  
16  public class SecretKeyEncryptionStrategyTestCase extends AbstractMuleTestCase
17  {
18  
19      public void testRoundTripEncryptionBlowfish() throws Exception
20      {
21          SecretKeyEncryptionStrategy ske = new SecretKeyEncryptionStrategy();
22          ske.setAlgorithm("Blowfish");
23          ske.setKey("shhhhh");
24          ske.initialise();
25  
26          byte[] b = ske.encrypt("hello".getBytes(), null);
27  
28          assertNotSame(new String(b), "hello");
29          String s = new String(ske.decrypt(b, null), "UTF-8");
30          assertEquals("hello", s);
31      }
32  
33      public void testRoundTripEncryptionTripleDES() throws Exception
34      {
35          SecretKeyEncryptionStrategy ske = new SecretKeyEncryptionStrategy();
36          ske.setAlgorithm("TripleDES");
37          ske.setKey("shhhhh");
38  
39          ske.initialise();
40  
41          byte[] b = ske.encrypt("hello".getBytes(), null);
42  
43          assertNotSame(new String(b), "hello");
44          String s = new String(ske.decrypt(b, null), "UTF-8");
45          assertEquals("hello", s);
46      }
47  }