The following code fragment provides an example of how to save an encrypted message.
/*SIMPLE FRAGMENT TO SAVE ENCRYPTED MESSAGE*/ MQeMsgHndl msgObj2, tmpMsg1, tmpMsg2; MQeMTrustAttributeHndl attr2; MQeMARSCryptorHndl mars; MQePrivateRegistryHndl getreg; MQePublicRegistryHndl pr; MQeInt64 confirmId2, confirmId3; MQERETURN rc; MQeExceptBlock exceptBlock; rc = mqe_uniqueValue(&exceptBlock, &confirmId2); rc = mqe_uniqueValue(&exceptBlock, &confirmId3); /* read the encrypted message without an attribute */ rc = mqeQueueManager_getMessage(newQM, &exceptBlock, &tmpMsg1, 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 */ rc = mqeMsg_new(&exceptBlock, &tmpMsg2); rc = mqeFields_putFields(tmpMsg2, &exceptBlock, MQeTring("encryptedMsg"), tmpMsg1); rc = mqeQueueManager_putMessage(newQM, &exceptBlock, localQMgrName, archiveQName, tmpMsg2, NULL, confirmId3); /* now decrypt and read the message ... */ /* create the cryptor */ rc = mqeMARSCryptor_new(&exceptBlock, &mars); /* create an attribute using the cryptor */ rc = mqeMTrustAttribute_new(&exceptBlock, &attr2, NULL, mars, NULL); /* open the private registry belonging to the target */ rc = mqePrivateRegistry_new(&exceptBlock, &getreg); rc = mqePrivateRegistry_activate(getreg, &exceptBlock, MQeStrinh("Bruce8"), MQeString(".//MQeNode_PrivateRegistry"), MQeString("12345678"), MQeString("It_is_a_secret"), NULL, NULL); /* set the private registry in the attribute */ rc = mqeMTrustAttribute_setPrivateRegistry(attr2, &exceptBlock, getreg); /* open a public registry to get the sender's certificate */ rc = mqePublicRegistry_new(&exceptBlock, &pr); rc = mqePublicRegistry_activate(pr, &exceptBlock, MQeString("MQeNode_PublicRegistry"), MQeString(".//")); /* set the public registry in the attribute */ rc = mqeMTrustAttribute_setPublicRegistry(attr2, &exceptBlock, pr); /* set a home server, which is used to find the certificate*/ /* if it is not already in the public registry */ rc = mqeMTrustAttribute_setHomeServer(attr2, &exceptBlock, MQeString(MyHomeServer ":8082")); /* decrypt the message by unwrapping it */ rc = mqeMsg_unwrapMsgObject(tmpMsg1, &exceptBlock, &msObj2, attr2);
/*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 */ } }