1 package net.sourceforge.jdpapi;
2
3 import java.io.File;
4
5 import junit.framework.TestCase;
6
7
8 public class DataProtectorTestCase extends TestCase {
9
10 static {
11 System.load(new File("target/jdpapi-native.dll").getAbsolutePath());;
12 }
13
14 public void testProtect() {
15 DataProtector p = new DataProtector();
16
17 byte [] data = p.protect("my key");
18
19 assertEquals("my key", p.unprotect(data));
20 }
21
22 public void testProtectWithEntropy() {
23 DataProtector p = new DataProtector("xxx".getBytes());
24 DataProtector p2 = new DataProtector("xxx".getBytes());
25
26 byte [] data = p.protect("my key");
27
28 assertEquals("my key", p2.unprotect(data));
29
30 p = new DataProtector("abc".getBytes());
31 p2 = new DataProtector("def".getBytes());
32
33 data = p.protect("my key");
34
35 try {
36 String result = p2.unprotect(data);
37 fail("Instead of exception, received: " + result);
38 } catch (DPAPIException expected) {
39
40 }
41 }
42 }