-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJDukptTest.java
99 lines (78 loc) · 4 KB
/
JDukptTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package test;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import java.math.BigInteger;
import org.junit.Test;
import org.phoegasus.jdukpt.core.JDukpt;
import org.phoegasus.jdukpt.utils.HexUtils;
public class JDukptTest {
private JDukpt jdukpt = new JDukpt();
private final String BDK = "A1A1A1A1A1A1A1A1B2B2B2B2B2B2B2B2";
private final String KSN = "FFFF9876543210E00002";
private final String IPEK = "A96C9F83F9F06DEE02AD998E80E93A04";
private final String PIN_ENCRYPTION_KEY = "9CF81D08CAE5D532243C18102DAA811B";
private final String DATA_ENCRYPTION_KEY = "6960DF245AACBCF03469F75F2EC0CB86";
private final String CLEAR_DATA = "041226CBA987EDCB";
private final String PIN_VARIANT_ENCRYPTED_DATA = "51B0229A9278CECC";
private final String DATA_VARIANT_ENCRYPTED_DATA = "D667CEE04B7A0EB4";
@Test
public void testPinEncryptionString() throws Exception {
assertEquals(jdukpt.encryptPIN(BDK, KSN, CLEAR_DATA).toUpperCase(), PIN_VARIANT_ENCRYPTED_DATA);
}
@Test
public void testPinDecryptionString() throws Exception {
assertEquals(jdukpt.decryptPIN(BDK, KSN, PIN_VARIANT_ENCRYPTED_DATA).toUpperCase(), CLEAR_DATA);
}
@Test
public void testPinEncryptionByteArray() throws Exception {
assertArrayEquals(jdukpt.encryptPIN(HexUtils.hexToBytes(BDK), HexUtils.hexToBytes(KSN), HexUtils.hexToBytes(CLEAR_DATA)), HexUtils.hexToBytes(PIN_VARIANT_ENCRYPTED_DATA));
}
@Test
public void testPinDecryptionByteArray() throws Exception {
assertArrayEquals(jdukpt.decryptPIN(HexUtils.hexToBytes(BDK), HexUtils.hexToBytes(KSN), HexUtils.hexToBytes(PIN_VARIANT_ENCRYPTED_DATA)), HexUtils.hexToBytes(CLEAR_DATA));
}
@Test
public void testPinEncryptionBigInteger() throws Exception {
assertEquals(jdukpt.encryptPIN(new BigInteger(BDK, 16), new BigInteger(KSN, 16), new BigInteger(CLEAR_DATA, 16)), new BigInteger(PIN_VARIANT_ENCRYPTED_DATA, 16));
}
@Test
public void testPinDecryptionBigInteger() throws Exception {
assertEquals(jdukpt.decryptPIN(new BigInteger(BDK, 16), new BigInteger(KSN, 16), new BigInteger(PIN_VARIANT_ENCRYPTED_DATA, 16)), new BigInteger(CLEAR_DATA, 16));
}
@Test
public void testDataEncryptionString() throws Exception {
assertEquals(jdukpt.encryptData(BDK, KSN, CLEAR_DATA).toUpperCase(), DATA_VARIANT_ENCRYPTED_DATA);
}
@Test
public void testDataDecryptionString() throws Exception {
assertEquals(jdukpt.decryptData(BDK, KSN, DATA_VARIANT_ENCRYPTED_DATA).toUpperCase(), CLEAR_DATA);
}
@Test
public void testDataEncryptionByteArray() throws Exception {
assertArrayEquals(jdukpt.encryptData(HexUtils.hexToBytes(BDK), HexUtils.hexToBytes(KSN), HexUtils.hexToBytes(CLEAR_DATA)), HexUtils.hexToBytes(DATA_VARIANT_ENCRYPTED_DATA));
}
@Test
public void testDataDecryptionByteArray() throws Exception {
assertArrayEquals(jdukpt.decryptData(HexUtils.hexToBytes(BDK), HexUtils.hexToBytes(KSN), HexUtils.hexToBytes(DATA_VARIANT_ENCRYPTED_DATA)), HexUtils.hexToBytes(CLEAR_DATA));
}
@Test
public void testDataEncryptionBigInteger() throws Exception {
assertEquals(jdukpt.encryptData(new BigInteger(BDK, 16), new BigInteger(KSN, 16), new BigInteger(CLEAR_DATA, 16)), new BigInteger(DATA_VARIANT_ENCRYPTED_DATA, 16));
}
@Test
public void testDataDecryptionBigInteger() throws Exception {
assertEquals(jdukpt.decryptData(new BigInteger(BDK, 16), new BigInteger(KSN, 16), new BigInteger(DATA_VARIANT_ENCRYPTED_DATA, 16)), new BigInteger(CLEAR_DATA, 16));
}
@Test
public void testGenerateIpek() throws Exception {
assertEquals(jdukpt.generateIpek(new BigInteger(BDK, 16), new BigInteger(KSN, 16)), new BigInteger(IPEK, 16));
}
@Test
public void testDerivePINEncryptionKey() throws Exception {
assertEquals(jdukpt.derivePINEncryptionKey(new BigInteger(BDK, 16), new BigInteger(KSN, 16)), new BigInteger(PIN_ENCRYPTION_KEY, 16));
}
@Test
public void testDeriveDataEncryptionKey() throws Exception {
assertEquals(jdukpt.deriveDataEncryptionKey(new BigInteger(BDK, 16), new BigInteger(KSN, 16)), new BigInteger(DATA_ENCRYPTION_KEY, 16));
}
}