use of org.jpos.util.SimpleMsg in project jPOS by jpos.
the class BaseSMAdapter method encryptData.
/**
* Encrypt Data Block.
*
* @param cipherMode block cipher mode
* @param kd DEK or ZEK key used to encrypt data
* @param data data to be encrypted
* @param iv initial vector
* @return encrypted data
* @throws SMException
*/
@Override
public byte[] encryptData(CipherMode cipherMode, SecureDESKey kd, byte[] data, byte[] iv) throws SMException {
List<Loggeable> cmdParameters = new ArrayList<Loggeable>();
cmdParameters.add(new SimpleMsg("parameter", "Block Cipher Mode", cipherMode));
if (kd != null)
cmdParameters.add(new SimpleMsg("parameter", "Data key", kd));
if (data != null)
cmdParameters.add(new SimpleMsg("parameter", "Data", ISOUtil.hexString(data)));
if (iv != null)
cmdParameters.add(new SimpleMsg("parameter", "Initialization Vector", ISOUtil.hexString(iv)));
LogEvent evt = new LogEvent(this, "s-m-operation");
evt.addMessage(new SimpleMsg("command", "Encrypt Data", cmdParameters));
byte[] encData = null;
try {
encData = encryptDataImpl(cipherMode, kd, data, iv);
List<Loggeable> r = new ArrayList<Loggeable>();
r.add(new SimpleMsg("result", "Encrypted Data", encData));
if (iv != null)
r.add(new SimpleMsg("result", "Initialization Vector", iv));
evt.addMessage(new SimpleMsg("results", r));
} catch (Exception e) {
evt.addMessage(e);
throw e instanceof SMException ? (SMException) e : new SMException(e);
} finally {
Logger.log(evt);
}
return encData;
}
use of org.jpos.util.SimpleMsg in project jPOS by jpos.
the class BaseSMAdapter method exportKey.
@Override
public byte[] exportKey(SecureDESKey key, SecureDESKey kek) throws SMException {
SimpleMsg[] cmdParameters = { new SimpleMsg("parameter", "Key", key), new SimpleMsg("parameter", "Key-Encrypting Key", kek) };
LogEvent evt = new LogEvent(this, "s-m-operation");
evt.addMessage(new SimpleMsg("command", "Export Key", cmdParameters));
byte[] result = null;
try {
result = exportKeyImpl(key, kek);
evt.addMessage(new SimpleMsg("result", "Exported Key", result));
} catch (Exception e) {
evt.addMessage(e);
throw e instanceof SMException ? (SMException) e : new SMException(e);
} finally {
Logger.log(evt);
}
return result;
}
use of org.jpos.util.SimpleMsg in project jPOS by jpos.
the class BaseSMAdapter method verifyIBMPINOffset.
@Override
public boolean verifyIBMPINOffset(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey pvk, String offset, String decTab, String pinValData, int minPinLen) throws SMException {
SimpleMsg[] cmdParameters = { new SimpleMsg("parameter", "account number", pinUnderKd1.getAccountNumber()), new SimpleMsg("parameter", "PIN under Data Key 1", pinUnderKd1), new SimpleMsg("parameter", "Data Key 1", kd1), new SimpleMsg("parameter", "PVK", pvk), new SimpleMsg("parameter", "Pin block format", pinUnderKd1.getPINBlockFormat()), new SimpleMsg("parameter", "decimalisation table", decTab), new SimpleMsg("parameter", "PIN validation data", pinValData), new SimpleMsg("parameter", "minimum PIN length", minPinLen), new SimpleMsg("parameter", "offset", offset) };
LogEvent evt = new LogEvent(this, "s-m-operation");
evt.addMessage(new SimpleMsg("command", "Verify PIN offset", cmdParameters));
try {
boolean r = verifyIBMPINOffsetImpl(pinUnderKd1, kd1, pvk, offset, decTab, pinValData, minPinLen);
evt.addMessage(new SimpleMsg("result", "Verification status", r ? "valid" : "invalid"));
return r;
} catch (Exception e) {
evt.addMessage(e);
throw e instanceof SMException ? (SMException) e : new SMException(e);
} finally {
Logger.log(evt);
}
}
use of org.jpos.util.SimpleMsg in project jPOS by jpos.
the class BaseSMAdapter method calculateIBMPINOffset.
@Override
public String calculateIBMPINOffset(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey pvk, String decTab, String pinValData, int minPinLen, List<String> excludes) throws SMException {
List<Loggeable> cmdParameters = new ArrayList<Loggeable>();
cmdParameters.add(new SimpleMsg("parameter", "account number", pinUnderKd1.getAccountNumber()));
cmdParameters.add(new SimpleMsg("parameter", "PIN under Data Key 1", pinUnderKd1));
cmdParameters.add(new SimpleMsg("parameter", "Data Key 1", kd1));
cmdParameters.add(new SimpleMsg("parameter", "PVK", pvk));
cmdParameters.add(new SimpleMsg("parameter", "decimalisation table", decTab));
cmdParameters.add(new SimpleMsg("parameter", "PIN validation data", pinValData));
cmdParameters.add(new SimpleMsg("parameter", "minimum PIN length", minPinLen));
if (excludes != null && !excludes.isEmpty())
cmdParameters.add(new SimpleMsg("parameter", "Excluded PINs list", excludes));
LogEvent evt = new LogEvent(this, "s-m-operation");
evt.addMessage(new SimpleMsg("command", "Calculate PIN offset", cmdParameters.toArray(new Loggeable[cmdParameters.size()])));
String result = null;
try {
result = calculateIBMPINOffsetImpl(pinUnderKd1, kd1, pvk, decTab, pinValData, minPinLen, excludes);
evt.addMessage(new SimpleMsg("result", "Calculated PIN offset", result));
} catch (Exception e) {
evt.addMessage(e);
throw e instanceof SMException ? (SMException) e : new SMException(e);
} finally {
Logger.log(evt);
}
return result;
}
use of org.jpos.util.SimpleMsg in project jPOS by jpos.
the class BaseSMAdapter method translateKeyScheme.
@Override
public SecureDESKey translateKeyScheme(SecureDESKey key, KeyScheme destKeyScheme) throws SMException {
SimpleMsg[] cmdParameters = { new SimpleMsg("parameter", "Key", key), new SimpleMsg("parameter", "Destination Key Scheme", destKeyScheme) };
LogEvent evt = new LogEvent(this, "s-m-operation");
evt.addMessage(new SimpleMsg("command", "Translate Key Scheme", cmdParameters));
SecureDESKey result = null;
try {
result = translateKeySchemeImpl(key, destKeyScheme);
evt.addMessage(new SimpleMsg("result", "Translate Key Scheme", result));
} catch (Exception e) {
evt.addMessage(e);
throw e instanceof SMException ? (SMException) e : new SMException(e);
} finally {
Logger.log(evt);
}
return result;
}
Aggregations