For an explanation about MQePrivateRegistry and MQePublicRegistry (used in the following example) see Private registry serviceand Public registry service.
/*SIMPLE PROTECT FRAGMENT */ { MQeMsgObject msgObj = null; MQeMTrustAttribute attr = null; long confirmId = MQe.uniqueValue(); try { trace(">>>putMessage from Bruce1 intended for Bruce8" + " to target Q using MQeMTrustAttribute with MARSCryptor "); /* create the cryptor */ MQeMARSCryptor mars = new MQeMARSCryptor(); /* create an attribute using the cryptor */ attr = new MQeMTrustAttribute(null, mars, null); /* open the private registry belonging to the sender */ String EntityName = "Bruce1"; String PIN = "12345678"; Object Passwd = "It_is_a_secret"; MQePrivateRegistry sendreg = new MQePrivateRegistry(); sendreg.activate(EntityName, ".\\MQeNode_PrivateRegistry", PIN, Passwd, null, null ); /* set the private registry in the attribute */ attr.setPrivateRegistry(sendreg ); /* set the target (recipient) name in the attribute */ attr.setTarget("Bruce8"); /* open a public registry to get the target's certificate */ MQePublicRegistry pr = new MQePublicRegistry(); pr.activate("MQeNode_PublicRegistry", ".\\"); /* set the public registry in the attribute */ attr.setPublicRegistry(pr); /* set a home server, which is used to find the certificate*/ /* if it is not already in the public registry */ attr.setHomeServer(MyHomeServer +":8082"); /* create the message */ msgObj =new MQeMsgObject(); msgObj.putAscii("MsgData","0123456789abcdef..."); /* put the message using the attribute */ newQM.putMessage(targetQMgrName, targetQName, msgObj, attr, confirmId ); trace(">>>MTrustAttribute protected msg put OK..."); } catch (Exception e) { trace(">>>on exception try resend exactly once..."); msgObj.putBoolean(MQe.Msg_Resend, true); newQM.putMessage(targetQMgrName, targetQName, msgObj, attr, confirmId ); } } /*SIMPLE UNPROTECT FRAGMENT */ { MQeMsgObject msgObj2 = null; MQeMTrustAttribute attr2 = null; long confirmId2 = MQe.uniqueValue(); try { trace(">>>getMessage from Bruce1 intended for Bruce8" + " from target Q using MQeMTrustAttribute with MARSCryptor "); /* create the cryptor */ MQeMARSCryptor mars = new MQeMARSCryptor(); /* create an attribute using the cryptor */ attr2 = new MQeMTrustAttribute(null, mars, null); /* open the private registry belonging to the target */ String EntityName = "Bruce8"; String PIN = "12345678"; Object Passwd = "It_is_a_secret"; MQePrivateRegistry getreg = new MQePrivateRegistry(); getreg.activate(EntityName, ".\\MQeNode_PrivateRegistry", PIN, Passwd, null, null ); /* set the private registry in the attribute */ attr2.setPrivateRegistry(getreg); /* open a public registry to get the sender's certificate */ MQePublicRegistry pr = new MQePublicRegistry(); pr.activate("MQeNode_PublicRegistry", ".\\"); /* set the public registry in the attribute */ attr2.setPublicRegistry(pr); /* set a home server, which is used to find the certificate*/ /* if it is not already in the public registry */ attr2.setHomeServer(MyHomeServer +":8082"); /* get the message using the attribute */ msgObj2 = newQM.getMessage(targetQMgrName, targetQName, null, attr2, confirmId2 ); trace(">>>MTrustAttribute protected msg = " + msgObj2.getAscii("MsgData")); } catch (Exception e) { /*exception may have left */ newQM.undo(targetQMgrName, /*message locked on queue */ targetQName, confirmId2 ); /*undo just in case */ e.printStackTrace(); /*show exception reason */ } }
Parent topic: Message level security