MSG newmsg=msg;
HBCIPassportInternal passport=(HBCIPassportInternal)handlerdata.getPassport();
if (passport.hasInstEncKey()) {
String msgName = msg.getName();
MsgGen gen=handlerdata.getMsgGen();
Node msgNode = msg.getSyntaxDef(msgName, gen.getSyntax());
String dontcryptAttr = ((Element)msgNode).getAttribute("dontcrypt");
if (dontcryptAttr.length() == 0) {
try {
setParam("secfunc",passport.getCryptFunction());
setParam("keytype",passport.getCryptKeyType());
setParam("blz",passport.getBLZ());
setParam("country",passport.getCountry());
setParam("keyuserid",passport.getInstEncKeyName());
setParam("keynum",passport.getInstEncKeyNum());
setParam("keyversion",passport.getInstEncKeyVersion());
setParam("cid",passport.getCID());
setParam("sysId",passport.getSysId());
setParam("role","1");
setParam("alg",passport.getCryptAlg());
setParam("mode",passport.getCryptMode());
setParam("compfunc","0"); // TODO: spaeter kompression implementieren
byte[][] crypteds=passport.encrypt(getPlainString());
String msgPath=msg.getPath();
String dialogid=msg.getValueOfDE(msgPath+".MsgHead.dialogid");
String msgnum=msg.getValueOfDE(msgPath+".MsgHead.msgnum");
String segnum=msg.getValueOfDE(msgPath+".MsgTail.SegHead.seq");
Date d=new Date();
gen.set(newName+".CryptData.data","B"+new String(crypteds[1],Comm.ENCODING));
gen.set(newName+".CryptHead.CryptAlg.alg",u_alg);
gen.set(newName+".CryptHead.CryptAlg.mode",u_mode);
gen.set(newName+".CryptHead.CryptAlg.enckey","B"+new String(crypteds[0],Comm.ENCODING));
gen.set(newName+".CryptHead.CryptAlg.keytype",u_keytype);
gen.set(newName+".CryptHead.SecIdnDetails.func",(newmsg.getName().endsWith("Res")?"2":"1"));
gen.set(newName+".CryptHead.KeyName.KIK.blz",u_blz);
gen.set(newName+".CryptHead.KeyName.KIK.country",u_country);
gen.set(newName+".CryptHead.KeyName.userid",u_keyuserid);
gen.set(newName+".CryptHead.KeyName.keynum",u_keynum);
gen.set(newName+".CryptHead.KeyName.keyversion",u_keyversion);
gen.set(newName+".CryptHead.SecProfile.method",passport.getProfileMethod());
gen.set(newName+".CryptHead.SecProfile.version",passport.getProfileVersion());
if (passport.getSysStatus().equals("0")) {
gen.set(newName+".CryptHead.SecIdnDetails.cid","B"+u_cid);
} else {
gen.set(newName+".CryptHead.SecIdnDetails.sysid",u_sysId);
}
gen.set(newName+".CryptHead.SecTimestamp.date",HBCIUtils.date2StringISO(d));
gen.set(newName+".CryptHead.SecTimestamp.time",HBCIUtils.time2StringISO(d));
gen.set(newName+".CryptHead.role",u_role);
gen.set(newName+".CryptHead.secfunc",u_secfunc);
gen.set(newName+".CryptHead.compfunc",u_compfunc);
gen.set(newName+".MsgHead.dialogid",dialogid);
gen.set(newName+".MsgHead.msgnum",msgnum);
gen.set(newName+".MsgTail.msgnum",msgnum);
if (newName.endsWith("Res")) {
gen.set(newName+".MsgHead.MsgRef.dialogid",dialogid);
gen.set(newName+".MsgHead.MsgRef.msgnum",msgnum);
}
newmsg=gen.generate(newName);
// renumerate crypto-segments
for (int i=1;i<=2;i++) {
SEG seg=(SEG)(((MultipleSEGs)((newmsg.getChildContainers()).get(i))).getElements().get(0));
seg.setSeq(997+i,SyntaxElement.ALLOW_OVERWRITE);