var version = globalMap.get('version');
var instalacion = globalMap.get('instalacion');
var did = globalMap.get('did');
// Calculamos la llave (Aqui algoritmo simple de llave dinamica conocido por ambas partes):
// concatenar fecha con version e instalacion
// -> Un mensaje/ticket/cadena de ayer no esta autorizada para hoy
var llave = DateUtil.getCurrentDate("yyyyMMdd") + version + instalacion + did;
// Vector de inicializacion constante y conocido por ambas partes
var iv = globalMap.get('iv');
try{
// Cifrar campos sensibles
// A modo ilustrativo solo consideraremos nombres y apellidos
tmp['PID']['PID.5']['PID.5.2'] = new Packages.crypt.Crypt.encrypt(llave,iv,msg['PacNombre'].toString());
tmp['PID']['PID.5']['PID.5.1'] = new Packages.crypt.Crypt.encrypt(llave,iv,msg['PacApell1'].toString());
tmp['PID']['PID.6']['PID.6.1'] = new Packages.crypt.Crypt.encrypt(llave,iv,msg['PacApell2'].toString());
}catch(e){
//Aqui haremos algo con la excepcion que ocurra
logger.error("Error descifrando ticket: " + e);
channelMap.put('responseStatusCode', '401');
return -1;
}