Usage guide for C

  1. The following code protects an MQeFields structure using MQeLocalSecure:
       /* write to a file */
       MQeFieldsAttrHndl hAttr = NULL;
       MQeStringHndl     hKeySeed = NULL, hDir = NULL, hFile = NULL;
       MQeStringHndl     hFieldName = NULL, hFieldData = NULL;
       MQeExceptBlock    exceptBlock; 
       MQeLocalSecureHndl hLocalSecure = NULL;
       MQeFieldsHndl     hData = NULL;
       MQEBYTE outBuf[128];
       MQEINT32 bufLen = 128;
     
       MQERETURN rc;
     
       /* create a key seed string */
       rc = mqeString_newChar8(&exceptBlock, 
    										&hKeySeed, 
    											"my secret key");
       /* create a new attribute with a RC4 cryptor */
       rc = mqeFieldsAttr_new(&exceptBlock, 
    										hAttr, NULL, 
    										MQE_RC4_CRYPTOR_CLASS_NAME, 
    										NULL, hKeySeed);
       /* create a dir string */
       rc = mqeString_newChar8( &exceptBlock, &hDir, ".\\");
       /* create a file name string */
       rc = mqeString_newChar8( &exceptBlock, 
    										&hFile,
    										"localSecureFile.txt");
       /* create an MQeLocalSecure */
       rc = mqeLocalSecure_new( &exceptBlock, &hLocalSecure);
       /* open file */
       rc = mqeLocalSecure_open(hLocalSecure, &exceptBlock, hDir, hFile);      
       /* create a data Fields */
       rc = mqeFields_new(&exceptBlock, &hData);
       /* add some test data */
       rc = mqeString_newChar8(&exceptBlock, 
    										&hFieldName, 
    										"testdata");
       rc = mqeString_newChar8(&exceptBlock, 
    										&hFieldData, 
    										"0123456789abcdef....");
       rc = mqeFields_putAscii(hData, &exceptBlock, 
    										hFieldName, hFieldData);
       /* dump (protect) data Fields */
       rc = mqeFields_dump(hData, &exceptBlock, 
    									outBuf, &buflen);
       /* write to .\\ocalSecureFile.txt */
       rc = mqeLocalSecure_write(hLocalSecure, &exceptBlock, 
    											outBuf, bufLen, hAttr, NULL);
     
       /* read from a file */
       MQeFieldsAttrHndl hAttr = NULL;
       MQeStringHndl   hKeySeed = NULL, hDir = NULL, hFile = NULL;
       MQeStringHndl   hFieldName = NULL, hFieldData = NULL;
       MQeExceptBlock  exceptBlock;
       MQeLocalSecureHndl hLocalSecure = NULL;
       MQERETURN rc;
       MQEBYTE outBuf[128];
       MQEINT32 bufLen = 128;
     
       /* create a key seed string */
       rc = mqeString_newChar8(&exceptBlock, 
    										&hKeySeed, 
    										"my secret key");
       /* create a new attribute with a RC4 cryptor */
       rc = mqeFieldsAttr_new(&exceptBlock, 
    										&hAttr, NULL, 
    										MQE_RC4_CRYPTOR_CLASS_NAME, 
    										NULL, hKeySeed);
       /* create a dir string */
       rc = mqeString_newChar8( &exceptBlock, 
    										&hDir, ".\\");
       /* create a file name string */
       rc = mqeString_newChar8( &exceptBlock, 
    										&hFile, 
    										"localSecureFile.txt");
       /* create an MQeLocalSecure */
       rc = mqeLocalSecure_new( &exceptBlock, 
    										&hLocalSecure);
       /* open file */
       rc = mqeLocalSecure_open(hLocalSecure, &exceptBlock, 
    										hDir, hFile);      
       /* read from .\\ocalSecureFile.txt */
       rc = mqeLocalSecure_read(hLocalSecure, 
    										&exceptBlock, outBuf, 
    										&Buflen, hAttr, NULL);
       /* create a data Fields */
       rc = mqeFields_new(&exceptBlock, &hData);
       /* restore data Fields */
       rc = mqeFields_restore(hData, &exceptBlock, 
    										outBuf, bufLen);
       /* read test data */
       rc = mqeString_newChar8(&exceptBlock, &hFieldName, 
    										"testdata");
       rc = mqeFields_getAscii(hData, &exceptBlock, 
    										&hFieldData, hFieldName);
     
     
    
  2. The following code protects an MQeFields structure without using MQeLocalSecure:
       /* dump to a buffer */
       MQeFieldsAttrHndl hAttr = NULL;
       MQeStringHndl     hKeySeed = NULL, hFieldName = 
    												NULL, hFieldData = NULL;
       MQeExceptBlock    exceptBlock; 
       MQeFieldsHndl     hData = NULL;
       MQEBYTE           outBuf[128];
       MQEINT32          bufLen = 128;
       MQERETURN rc;
     
       /* create a key seed string */
       rc = mqeString_newChar8(&exceptBlock, 
    										&hKeySeed, 
    										"my secret key");
       /* create a new attribute with a RC4 cryptor */
       rc = mqeFieldsAttr_new(&exceptBlock, 
    										&hAttr, NULL, 
    										MQE_RC4_CRYPTOR_CLASS_NAME, 
    										NULL, hKeySeed);
       /* create a data Fields */
       rc = mqeFields_new(&exceptBlock, &hData);
       /* set the attribute to the data Fields */
       rc = mqeFields_setAttribute(hData, &exceptBlock, hAttr);
       /* add some test data */
       rc = mqeString_newChar8(&exceptBlock, 
    										&hFieldName, 
    										"testdata");
       rc = mqeString_newChar8(&exceptBlock, 
    										&hFieldData, 
    										"0123456789abcdef....");
       rc = mqeFields_putAscii(hData, &exceptBlock, 
    										hFieldName, hFieldData);
       /* dump (protect) data Fields */
       rc = mqeFields_dump(hData, &exceptBlock, 
    									outBuf, &bufLen);
     
       /* restor from a buffer */
       MQeFieldsAttrHndl hAttr = NULL;
       MQeStringHndl     hKeySeed = NULL, hFieldName = 
    													NULL, hFieldData = NULL;
       MQeExceptBlock    exceptBlock; 
       MQERETURN rc;
       MQEBYTE           outBuf[128];
       MQEINT32          bufLen = 128;
     
       ...
       /* assume protected data is in inBuf 
    			and its length is in bufLen */
       
       /* create a key seed string */
       rc = mqeString_newChar8(&exceptBlock, 
    										&hKeySeed, 
    										"my secret key");
       /* create a new attribute with a RC4 cryptor */
       rc = mqeFieldsAttr_new(&exceptBlock, 
    										&hAttr, NULL,
    										 MQE_RC4_CRYPTOR_CLASS_NAME, 
    										 NULL, hKeySeed);
       /* create a data Fields */
       rc = mqeFields_new(&exceptBlock, &hData);
       /* set the attribute to the data Fields */
       rc = mqeFields_setAttribute(hData, &exceptBlock, hAttr);
       /* restore data Fields */
       rc = mqeFields_restore(hData, &exceptBlock, 
    										inBuf, bufLen);
       /* read test data */
       rc = mqeString_newChar8(&exceptBlock, 
    										&hFieldName, "testdata");
       rc = mqeFields_getAscii(hData, &exceptBlock, 
    										&hFieldData, hFieldName);
     
    


© IBM Corporation 2002. All Rights Reserved