The following code fragment provides an example of how to save an encrypted message.
/*SIMPLE FRAGMENT TO SAVE ENCRYPTED MESSAGE*/ { MQeMsgObject msgObj2 = null; MQeMTrustAttribute attr2 = null; long confirmId2 = MQe.uniqueValue(); long confirmId3 = MQe.uniqueValue(); try { trace(">>>getMessage from Bruce1 intended for Bruce8" + " from target Q using MQeMTrustAttribute with MARSCryptor "); /* read the encrypted message without an attribute */ MQeMsgObject tmpMsg1 = newQM.getMessage(targetQMgrName, targetQName, null, null, confirmId2 ); /* save the encrypted message - we cannot put it directly */ /* to another queue because of the origin queue manager */ /* data. Embed it in another message */ MQeMsgObject tmpMsg2 = new MQeMsgObject(); tmpMsg2.putFields("encryptedMsg", tmpMsg1); newQM.putMessage(localQMgrName, archiveQName, tmpMsg2, null, confirmId3); trace(">>>encrypted message saved locally"); /* now decrypt and read the message & */ /* 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"); /* decrypt the message by unwrapping it */ msgObj2 = tmpMsg1.unwrapMsgObject(attr2); 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: Non-repudiation