Skip to content

Commit e2f7808

Browse files
authored
Merge pull request #676 from fgonzal/fix/ksn-align-with-10-5-5
Serialize KSNs using 10-5-5.
2 parents b7db31f + 6966ac3 commit e2f7808

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

jpos/src/main/java/org/jpos/security/KeySerialNumber.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.nio.ByteBuffer;
2727
import java.util.Objects;
2828

29-
3029
/**
3130
* Key Serial Number (also called Key Name in the ANSI X9.24).
3231
* Needed for deriving the Transaction Key when DUKPT (Derived Unique Key Per
@@ -96,7 +95,7 @@ public byte[] getBaseKeyIDBytes () {
9695
* @return a String representing the device ID.
9796
*/
9897
public String getDeviceID () {
99-
return String.format ("%06X", deviceId);
98+
return String.format ("%05X", deviceId);
10099
}
101100

102101
/**
@@ -119,7 +118,7 @@ public byte[] getDeviceIDBytes () {
119118
* @return a String representing the transaction counter.
120119
*/
121120
public String getTransactionCounter () {
122-
return String.format ("%06X", transactionCounter);
121+
return String.format ("%05X", transactionCounter);
123122
}
124123

125124
/**

jpos/src/test/java/org/jpos/security/KeySerialNumberTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@
2828

2929
public class KeySerialNumberTest {
3030

31-
3231
@Test
33-
public void testDump() throws Throwable {
32+
public void testStringConstructor() throws Throwable {
3433
PrintStream p = new PrintStream(new ByteArrayOutputStream(), true, "UTF-8");
3534
Object[] objects = new Object[1];
3635
p.format("testKeySerialNumberParam1", objects);
37-
new KeySerialNumber("FFFF987654", "3210E", "000008")
38-
.dump(p, "testKeySerialNumberIndent");
36+
KeySerialNumber ksn = new KeySerialNumber("FFFF987654", "3210E", "00008");
37+
ksn.dump(p, "testKeySerialNumberIndent");
38+
assertEquals("FFFF987654", ksn.getBaseKeyID());
39+
assertEquals("3210E", ksn.getDeviceID());
40+
assertEquals("00008", ksn.getTransactionCounter());
3941
assertTrue(true, "Test completed without Exception");
4042
}
4143

@@ -44,8 +46,8 @@ public void testBinaryConstructor() {
4446
byte[] ksnBin = ISOUtil.hex2byte("9876543210E00008");
4547
KeySerialNumber ksn = new KeySerialNumber(ksnBin);
4648
assertEquals("FFFF987654", ksn.getBaseKeyID());
47-
assertEquals("03210E", ksn.getDeviceID());
48-
assertEquals("000008", ksn.getTransactionCounter());
49+
assertEquals("3210E", ksn.getDeviceID());
50+
assertEquals("00008", ksn.getTransactionCounter());
4951
}
5052

5153
@Test

0 commit comments

Comments
 (0)