use of org.jpos.util.SimpleMsg in project jPOS by jpos.
the class BaseSMAdapter method decryptData.
/**
* Decrypt Data Block.
*
* @param cipherMode block cipher mode
* @param kd DEK or ZEK key used to decrypt data
* @param data data to be decrypted
* @param iv initial vector
* @return decrypted data
* @throws SMException
*/
@Override
public byte[] decryptData(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", "Decrypt Data", cmdParameters));
byte[] decData = null;
try {
decData = decryptDataImpl(cipherMode, kd, data, iv);
List<Loggeable> r = new ArrayList<Loggeable>();
r.add(new SimpleMsg("result", "Decrypted Data", decData));
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 decData;
}
use of org.jpos.util.SimpleMsg in project jPOS by jpos.
the class BaseSMAdapter method encryptPIN.
@Override
public EncryptedPIN encryptPIN(String pin, String accountNumber, boolean extract) throws SMException {
accountNumber = extract ? EncryptedPIN.extractAccountNumberPart(accountNumber) : accountNumber;
SimpleMsg[] cmdParameters = { new SimpleMsg("parameter", "clear pin", pin), new SimpleMsg("parameter", "account number", accountNumber) };
LogEvent evt = new LogEvent(this, "s-m-operation");
evt.addMessage(new SimpleMsg("command", "Encrypt Clear PIN", cmdParameters));
EncryptedPIN result = null;
try {
result = encryptPINImpl(pin, accountNumber);
evt.addMessage(new SimpleMsg("result", "PIN under LMK", 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 verifyCVV.
@Override
public boolean verifyCVV(String accountNo, SecureDESKey cvkA, SecureDESKey cvkB, String cvv, Date expDate, String serviceCode) throws SMException {
SimpleMsg[] cmdParameters = { new SimpleMsg("parameter", "account number", accountNo), new SimpleMsg("parameter", "cvk-a", cvkA == null ? "" : cvkA), new SimpleMsg("parameter", "cvk-b", cvkB == null ? "" : cvkB), new SimpleMsg("parameter", "CVV/CVC", cvv), new SimpleMsg("parameter", "Exp date", expDate), new SimpleMsg("parameter", "Service code", serviceCode) };
LogEvent evt = new LogEvent(this, "s-m-operation");
evt.addMessage(new SimpleMsg("command", "Verify CVV/CVC", cmdParameters));
try {
boolean r = verifyCVVImpl(accountNo, cvkA, cvkB, cvv, expDate, serviceCode);
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 calculateSignature.
@Override
public byte[] calculateSignature(MessageDigest hash, SecurePrivateKey privateKey, byte[] data) throws SMException {
List<Loggeable> cmdParameters = new ArrayList<Loggeable>();
cmdParameters.add(new SimpleMsg("parameter", "Hash Identifier", hash));
cmdParameters.add(new SimpleMsg("parameter", "Private Key", privateKey));
cmdParameters.add(new SimpleMsg("parameter", "data", data));
LogEvent evt = new LogEvent(this, "s-m-operation");
evt.addMessage(new SimpleMsg("command", "Generate data signature", cmdParameters));
byte[] result = null;
try {
result = calculateSignatureImpl(hash, privateKey, data);
evt.addMessage(new SimpleMsg("result", "Data Signature", 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 verifyPVV.
@Override
public boolean verifyPVV(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey pvkA, SecureDESKey pvkB, int pvki, String pvv) 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-A", pvkA == null ? "" : pvkA), new SimpleMsg("parameter", "PVK-B", pvkB == null ? "" : pvkB), new SimpleMsg("parameter", "pvki", pvki), new SimpleMsg("parameter", "pvv", pvv) };
LogEvent evt = new LogEvent(this, "s-m-operation");
evt.addMessage(new SimpleMsg("command", "Verify a PIN Using the VISA Method", cmdParameters));
try {
boolean r = verifyPVVImpl(pinUnderKd1, kd1, pvkA, pvkB, pvki, pvv);
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);
}
}
Aggregations