use of org.jpos.security.SecureDESKey in project jPOS by jpos.
the class JCESecurityModuleTest method testImportPINImplThrowsNullPointerException1.
@Test
public void testImportPINImplThrowsNullPointerException1() throws Throwable {
byte[] keyBytes = new byte[0];
try {
new JCESecurityModule().importPINImpl(new EncryptedPIN("testJCESecurityModulePinBlockHexString", (byte) 0, "testJCESecurityModuleAccountNumber"), new SecureDESKey((short) 100, "testJCESecurityModuleKeyType", keyBytes, "testString".getBytes()));
fail("Expected NullPointerException to be thrown");
} catch (NullPointerException ex) {
if (isJavaVersionAtMost(JAVA_14)) {
assertNull(ex.getMessage(), "ex.getMessage()");
} else {
assertEquals("Cannot invoke \"java.util.Map.containsKey(Object)\" because \"this.keyTypeToLMKIndex\" is null", ex.getMessage(), "ex.getMessage()");
}
}
}
use of org.jpos.security.SecureDESKey in project jPOS by jpos.
the class JCESecurityModuleTest method testTranslatePINImplThrowsNullPointerException.
@Test
public void testTranslatePINImplThrowsNullPointerException() throws Throwable {
try {
new JCESecurityModule().translatePINImpl(new EncryptedPIN("testString".getBytes(), (byte) 0, "testJCESecurityModuleAccountNumber"), null, new SecureDESKey(), (byte) 0);
fail("Expected NullPointerException to be thrown");
} catch (NullPointerException ex) {
if (isJavaVersionAtMost(JAVA_14)) {
assertNull(ex.getMessage(), "ex.getMessage()");
} else {
assertEquals("Cannot invoke \"org.jpos.security.SecureDESKey.getKeyBytes()\" because \"secureDESKey\" is null", ex.getMessage(), "ex.getMessage()");
}
}
}
use of org.jpos.security.SecureDESKey in project jPOS by jpos.
the class DUKPTTest method test_DUKPT.
private void test_DUKPT(String keyName, KeySerialNumber ksn, byte[] pinUnderDukpt, String pan, boolean tdes) throws Exception {
LogEvent evt = log.createInfo("test_DUKPT " + ksn);
evt.addMessage(ksn);
EncryptedPIN pin = new EncryptedPIN(pinUnderDukpt, SMAdapter.FORMAT01, pan);
SecureDESKey bdk = ks.getKey(keyName);
evt.addMessage(pin);
evt.addMessage(ksn);
evt.addMessage(bdk);
EncryptedPIN pinUnderLMK = sm.importPIN(pin, ksn, bdk, tdes);
evt.addMessage(pinUnderLMK);
evt.addMessage("<decrypted-pin>" + sm.decryptPIN(pinUnderLMK) + "</decrypted-pin>");
Logger.log(evt);
}
use of org.jpos.security.SecureDESKey in project jPOS by jpos.
the class DUKPTTest method test_dataEncrypt.
@Test
public void test_dataEncrypt() throws Exception {
SecureDESKey bdk = (SecureDESKey) ks.getKey("test-bdk");
byte[] original = "The quick brown fox jumps over the lazy dog".getBytes();
byte[] cryptogram = sm.dataEncrypt(bdk, original);
byte[] cleartext = sm.dataDecrypt(bdk, cryptogram);
assertEqual(original, cleartext);
cryptogram[0] = (byte) (cryptogram[0] ^ 0xAA);
try {
sm.dataDecrypt(bdk, cryptogram);
fail("SMException not raised");
} catch (Exception ignored) {
}
}
use of org.jpos.security.SecureDESKey in project jPOS by jpos.
the class JCESecurityModuleTest method translateKeySchemeImpl_Convert.
@Test
public void translateKeySchemeImpl_Convert() throws Throwable {
SecureDESKey pvk = new SecureDESKey(SMAdapter.LENGTH_DES3_2KEY, SMAdapter.TYPE_PVK + ":0X", "141E1DA3D2D7F3F4141E1DA3D2D7F3F4", "6FB1C8");
SecureDESKey conv = jcesecmod.translateKeySchemeImpl(pvk, KeyScheme.U);
assertEquals(pvk.getKeyLength(), conv.getKeyLength());
assertEquals(SMAdapter.TYPE_PVK + ":0U", conv.getKeyType());
assertArrayEquals(pvk.getKeyCheckValue(), conv.getKeyCheckValue());
assertEquals(KeyScheme.U, conv.getScheme());
assertEquals(pvk.getVariant(), conv.getVariant());
// TPK and ZPK uses same encription variant
assertArrayEquals(tpk.getKeyBytes(), conv.getKeyBytes());
}
Aggregations