1
2
3
4
5
6
7
8
9
10
11 package org.mule.mule.security;
12
13 import org.mule.security.SecretKeyEncryptionStrategy;
14 import org.mule.security.SecretKeyFactory;
15 import org.mule.tck.AbstractMuleTestCase;
16
17 public class SecretKeyEncryptionStrategyTestCase extends AbstractMuleTestCase
18 {
19
20 public void testRoundTripEncryptionBlowfish() throws Exception
21 {
22 SecretKeyEncryptionStrategy ske = new SecretKeyEncryptionStrategy();
23 ske.setAlgorithm("Blowfish");
24 ske.setKey("shhhhh");
25 ske.initialise();
26
27 byte[] b = ske.encrypt("hello".getBytes(), null);
28
29 assertNotSame(new String(b), "hello");
30 String s = new String(ske.decrypt(b, null), "UTF-8");
31 assertEquals("hello", s);
32 }
33
34 public void testRoundTripEncryptionBlowfishWithKeyFactory() throws Exception
35 {
36 SecretKeyEncryptionStrategy ske = new SecretKeyEncryptionStrategy();
37 ske.setAlgorithm("Blowfish");
38 ske.setKeyFactory(new SecretKeyFactory()
39 {
40 public byte[] getKey()
41 {
42 return "shhhh".getBytes();
43 }
44 });
45 ske.initialise();
46
47 byte[] b = ske.encrypt("hello".getBytes(), null);
48
49 assertNotSame(new String(b), "hello");
50 String s = new String(ske.decrypt(b, null), "UTF-8");
51 assertEquals("hello", s);
52 }
53
54 public void testRoundTripEncryptionTripleDES() throws Exception
55 {
56 SecretKeyEncryptionStrategy ske = new SecretKeyEncryptionStrategy();
57 ske.setAlgorithm("TripleDES");
58 ske.setKey("shhhhh");
59
60 ske.initialise();
61
62 byte[] b = ske.encrypt("hello".getBytes(), null);
63
64 assertNotSame(new String(b), "hello");
65 String s = new String(ske.decrypt(b, null), "UTF-8");
66 assertEquals("hello", s);
67 }
68
69 }