Usage guide

  1. The following pseudo-code protects an MQeFields object using MQeLocalSecure
    /*SIMPLE PROTECT FRAGMENT */
    			#define BUF_LENGTH		1000		/* assuming this is big enough */
     
    			MQeDESCryptorHndl	desC;
    			MQeAttributeHndl	attr;
    			MQeKeyHndl		localkey;
    			MQeFieldsHndl		myData;
    			MQEBYTE 		protectedData[BUF_LENGTH];
    			MQEINT32		bufLength	=	BUF_LENGTH;
    			MQERETURN		rc;
    			MQeExceptBlock	exceptBlock;
     
    			/*instantiate a DES cryptor */
    			rc = mqeDESCryptor_new(&exceptBlock, &desC);
                 			/*instantiate an Attribute using the DES cryptor */
    			rc = mqeAttribute_new(&exceptBlock, &attr, NULL, 
    											NULL, desC, NULL);
    			/*instantiate a base Key object */
    			rc = mqeKey_new(&exceptBlock, &localKey);
    			/*set the base Key object local key */
    			rc = mqeKey_setLocalKey(localKey, &exceptBlock, 
    												MQeString("my secret key"));
    			/*attach the key to the attribute */
    			rc = mqeAttribute_setKey(attr, &exceptBlock, localkey);
    			/*instantiate a MQeFields object */
                 		 	rc = mqeFields_new(&exceptBlock, &myData);
    			/*attach the attribute to the data object */
    			mqeFields_setAttribute(myData, &exceptBlock, attr);
    			/*add some test data */
    			rc = mqeFields_putAscii(myData, &exceptBlock, MQeString("testdata"), 
                                    MQeString("0123456789abcdef...."));
    			/*encode the data */
    			rc = mqeFields_dump(myData, &exceptBlock, protectedData, 
    													&bufLength, MQE_FALSE);
     
    			/* SIMPLE UNPROTECT FRAGMENT                                  */
    			#define BUF_LENGTH		1000		/* assuming this is big enough */
     
    			MQeDESCryptorHndl	desC2;
    			MQeAttributeHndl	attr2;
    			MQeLocalSecureHndl	ls2;
    			MQEBYTE 		outBuf[BUF_LENGTH];
    			MQEINT32		bufLength	=	BUF_LENGTH;
    			MQERETURN		rc;
    			MQeExceptBlock	exceptBlock;
     
    			/* instantiate a DES cryptor                                  */
    			rc = mqeDESCryptor_new(&exceptBlock, &desC2);
    			/* instantiate an attribute using the DES cryptor             */
      		             rc = mqeAttribute_new(&exceptBlock, 
    														&attr2, NULL, NULL, des2C, NULL);
    			/* instantiate a (a helper) LocalSecure object                */
    		               rc = mqeLocalSecure_new(&exceptBlock, &ls2);
    			/* open LocalSecure obj identifying target file and directory */
    			rc = mqeString_newChar8(&exceptBlock, &fileDir, ".\\");
    			rc = mqeLocalSecure_open(ls2,  &exceptBlock, MQeString(".\\"), 
                                      MQeString("TestSecureData.txt"));
     
    			/* use LocalSecure read to restore from target and decode data */
    			rc = mqeLocalSecure_read(ls2, &exceptBlock, outBuf, &bufLength, 
                                     attr2, MQeString("my secret key"));
     
    
  2. The following pseudo-code protects an MQeFields locally without using MQeLocalSecure.
    /*SIMPLE PROTECT FRAGMENT */
    			#define BUF_LENGTH		1000		/* assuming this is big enough */
     
    			MQeDESCryptorHndl	desC;
    			MQeAttributeHndl	attr;
    			MQeKeyHndl		localkey;
    			MQeFieldsHndl		myData;
    			MQEBYTE 		protectedData[BUF_LENGTH];
    			MQEINT32		bufLength	=	BUF_LENGTH;
    			MQERETURN		rc;
    			MQeExceptBlock	exceptBlock;
     
    			/*create a DES cryptor */
    			rc = mqeDESCryptor_new(&exceptBlock, &desC);
                 			/*create an Attribute using the DES cryptor */
    			rc = mqeAttribute_new(&exceptBlock,&attr, NULL, NULL, desC, NULL);
    			/*create a base Key object */
    			rc = mqeKey_new(&exceptBlock, &localKey);
    			/*set the base Key object local key */
    			rc = mqeKey_setLocalKey(localKey, &exceptBlock, 
    											 MQeString("my secret key"));
    			/*attach the key to the attribute */
    			rc = mqeAttribute_setKey(attr, &exceptBlock, localkey);
    			/*create a MQeFields object */
                 			rc = mqeFields_new(&exceptBlock, &myData);
    			/*attach the attribute to the data object */
    			mqeFields_setAttribute(myData, &exceptBlock, attr);
    			/*add some test data */
    			rc = mqeFields_putAscii(myData, &exceptBlock, 
                                    MQeString("testdata"), 
    											 MQeString("0123456789abcdef...."));
    			/*encode the data */
    			rc = mqeFields_dump(myData, &exceptBlock, protectedData, 
    										&bufLength, MQE_FALSE);
     
    			/* SIMPLE UNPROTECT FRAGMENT                                  */
    			#define BUF_LENGTH		1000		/* assuming this is big enough */
     
    			MQeDESCryptorHndl	desC2;
    			MQeAttributeHndl	attr2;
    			MQeKeyHndl		localKey2;
    			MQeFieldsHndl		myData2;
    			MQEBYTE 		protectedData[BUF_LENGTH];
    			MQEINT32		bufLength	=	BUF_LENGTH;
    			MQERETURN		rc;
    			MQeExceptBlock	exceptBlock;
     
    			/* read protected data into protectedData and set 
    				bufLength to the data length */
    			...
    			/* create a DES cryptor  */
    			rc = mqeDESCryptor_new(&exceptBlock, &desC2);
    			/*create an attribute using the DES cryptor             */
                  			rc = mqeAttribute_new(&exceptBlock, &attr2, 
                                                  NULL, NULL, des2C, NULL);
    			/* create a (a helper) LocalSecure object                */
                  			rc = mqeKey_new(&exceptBlock, &localKey);
    			/*set the base Key object local key */
    			rc = mqeKey_setLocalKey(localKey2, &exceptBlock, 
    											 MQeString("my secret key"));
    		        	/*attach the key to the attribute */
    			mqeAttribute_setKey(attr2, &exceptBlock, localkey2);
    			 /*create a new data object */
    			rc = mqeFields_new(&exceptBlock, &myData);
    			/*attach the attribute to the data object */
    			mqeFields_setAttribute(myData2, &exceptBlock, attr2);
    			/*decode the data */
    			mqeFields_restore(myData2, &exceptBlock, protectedData, 
    									 bufLength, MQE_FALSE);
     
    


© IBM Corporation 2000, 2003. All Rights Reserved