/*SIMPLE PROTECT FRAGMENT */ { MQeMsgObject msgObj = null; MQeMAttribute attr = null; long confirmId = MQe.uniqueValue(); try{ trace(">>>putMessage to target Q using MQeMAttribute" +" with 3DES Cryptor and key=my secret key"); /* create the cryptor */ MQe3DESCryptor tdes = new MQe3DESCryptor(); /* create an attribute using the cryptor */ attr = new MQeMAttribute(null,tdes,null ); /* create a local key */ MQeKey localkey = new MQeKey(); /* give it the key seed */ localkey.setLocalKey("my secret key"); /* set the key in the attribute */ attr.setKey(localkey ); /* create the message */ msgObj = new MQeMsgObject(); msgObj.putAscii("MsgData","0123456789abcdef..."); /* put the message using the attribute */ newQM.putMessage(targetQMgrName, targetQName, msgObj, attr, confirmId ); trace(">>>MAttribute 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; MQeMAttribute attr2 = null; long confirmId2 = MQe.uniqueValue(); try{ trace(">>>getMessage from target Q using MQeMAttribute"+ " with 3DES Cryptor and key=my secret key"); /* create the attribute - we do not have to specify the cryptor, */ /* the attribute can get this from the message itself */ attr2 = new MQeMAttribute(null,null,null ); /* create a local key */ MQeKey localkey = new MQeKey(); /* give it the key seed */ localkey.setLocalKey("my secret key"); /* set the key in the attribute */ attr2.setKey(localkey ); /* get the message using the attribute */ msgObj2 = newQM.getMessage(targetQMgrName, targetQName, null, attr2, confirmId2 ); trace(">>>unprotected MsgData = " + 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