This project has retired. For details please refer to its
Attic page.
AES128CryptorTest xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juddi.v3.client.cryptor;
18
19 import java.security.InvalidKeyException;
20 import java.security.NoSuchAlgorithmException;
21 import java.security.spec.InvalidKeySpecException;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24 import javax.crypto.NoSuchPaddingException;
25 import org.junit.Test;
26 import static org.junit.Assert.*;
27
28
29
30
31
32 public class AES128CryptorTest {
33
34 public AES128CryptorTest() {
35 }
36
37
38
39
40 @Test
41 public void testGetKey() {
42 try {
43 System.out.println("getKey");
44 AES128Cryptor instance = new AES128Cryptor();
45 String result = instance.getKey();
46 assertNotNull(result);
47 } catch (NoSuchAlgorithmException ex) {
48 Logger.getLogger(AES128CryptorTest.class.getName()).log(Level.SEVERE, null, ex);
49 } catch (InvalidKeySpecException ex) {
50 Logger.getLogger(AES128CryptorTest.class.getName()).log(Level.SEVERE, null, ex);
51 } catch (NoSuchPaddingException ex) {
52 Logger.getLogger(AES128CryptorTest.class.getName()).log(Level.SEVERE, null, ex);
53 } catch (InvalidKeyException ex) {
54 Logger.getLogger(AES128CryptorTest.class.getName()).log(Level.SEVERE, null, ex);
55 }
56 }
57
58
59
60
61 @Test
62 public void testEncrypt() throws Exception {
63 System.out.println("encrypt");
64 String str = "test";
65 AES128Cryptor instance = new AES128Cryptor();
66 String result = instance.encrypt(str);
67 assertNotEquals(str, result);
68 }
69
70
71
72
73 @Test
74 public void testExternalKey() throws Exception {
75 System.out.println("testExternalKey");
76 AES128Cryptor instance = new AES128Cryptor();
77 String result = instance.getKey();
78 System.getProperties().put("juddi.encryptionKeyFile.AES128Cryptor", "./src/test/resources/JUDDI-808/aes128.key");
79 String expResult = instance.getKey();
80 System.getProperties().remove("juddi.encryptionKeyFile.AES128Cryptor");
81 assertNotEquals("loading of external key failed", expResult, result);
82 String enc = instance.decrypt(instance.encrypt("test"));
83 assertEquals(enc, "test");
84 }
85
86
87
88
89 @Test
90 public void testDecrypt() throws Exception {
91 System.out.println("testDecrypt");
92 String str = "test";
93 AES128Cryptor instance = new AES128Cryptor();
94 String expResult = "test";
95 String result = instance.decrypt(instance.encrypt(str));
96 assertEquals(expResult, result);
97 }
98
99
100
101
102 @Test
103 public void testNewKey() throws Exception{
104 System.out.println("newKey");
105 AES128Cryptor instance = new AES128Cryptor();
106 String result = instance.newKey();
107 assertNotNull(result);
108 }
109
110 }