Encrypting a Password for Accessing Data in a PDM Database

 

The following code enables you to encrypt a password for access to PDM databases during the use of the CATDMUUtility and the CATDMUUtility2d.
  To encrypt a password, you must implement the CATIUExitCrypt interface, which contains the following two methods:

virtual HRESULT Code ( const void *iBuffer, size_t iLen, void **CodedBuffer, size_t *oCodedLen)=0;

Code a given buffer. 

  • param iBuffer: Input Buffer to be coded 
  • param iLen Length of the input buffer 
  • param oCodedBuffer Output Buffer. It must be allocated by the method Code
  • param oCodedLen Length of the output buffer 
  • return S_OK E_FAIL if the  coding is not successful

virtual HRESULT Decode (const void *iCodedBuffer, size_t iCodedLen, void **DecodedBuffer, size_t *oDecodedLen)=0;

Decode a given Buffer. 

  • param iCodedBuffer Input Buffer to be decoded 
  • param iCodedLen Length of the input buffer 
  • param oDecodedBuffer Output Buffer. It must be allocated by the method Decode
  • param oDecodedLen Length of the output buffer 
  • return S_OK E_FAIL if the decoding is not successful

 

Example:


// CATDDF_UExitCrypt.cpp
#include "CATDDF_UExitCrypt.h"

//#include <iostream.h>

#include <stdlib.h>

#include "CATErrorDef.h"
#include "CATError.h"

CATImplementClass(CATDDF_UExitCrypt, DataExtension, CATBaseUnknown, CATUExitCrypt);

// Tie the implementation to its interface
// ---------------------------------------
#include "TIE_CATIUExitCrypt.h"
TIE_CATIUExitCrypt(CATDDF_UExitCrypt);

//-----------------------------------------------------------------------------
CATDDF_UExitCrypt::CATDDF_UExitCrypt(): CATBaseUnknown()
{
}

//-----------------------------------------------------------------------------
CATDDF_UExitCrypt::~CATDDF_UExitCrypt()
{
}

//-----------------------------------------------------------------------------
HRESULT CATDDF_UExitCrypt::Code(const void * iDecodedBuffer, size_t iDecodedLen, void ** oCodedBuffer, size_t * oCodedLen)
{
HRESULT HR = CATReturnFailure;

HR = Decode(iDecodedBuffer, iDecodedLen, oCodedBuffer, oCodedLen);

return HR;
}

//-----------------------------------------------------------------------------
HRESULT CATDDF_UExitCrypt::Decode(const void * iCodedBuffer, size_t iCodedLen, void ** oDecodedBuffer, size_t * oDecodedLen)
{
HRESULT HR = CATReturnFailure;

*oDecodedLen = iCodedLen;
char ** pDecoded = new char * [iCodedLen];
*pDecoded = strdup((char *) iCodedBuffer);
int iMid = (iCodedLen-1)/2;
int iStart1 = 0;
int iStart2 = (iCodedLen-1)-iMid;
strncpy((*pDecoded)+iStart1, (char *) iCodedBuffer+iStart2, iMid);
strncpy((*pDecoded)+iStart2, (char *) iCodedBuffer+iStart1, iMid);
*oDecodedBuffer = (void *) *pDecoded;

HR = CATReturnSuccess;

return HR;
}

 

 


// CATDDF_UExitCrypt.h
#ifndef CATDDF_UExitCrypt_H
#define CATDDF_UExitCrypt_H

#include "CATBaseUnknown.h"

#include "CATIUExitCrypt.h"

#include "CATErrorDef.h"
#include <stdlib.h>

//-----------------------------------------------------------------------

/**
* Provide implementation for a CATUExitCrypt.
* <br>
* It implements the interfaces :
* <ol>
* <li>@see NavigatorInterfaces.CATIUExitCrypt
* </ol>
*/
class CATDDF_UExitCrypt: public CATBaseUnknown
{
CATDeclareClass;

public:

// Standard constructors and destructors for an implementation class
// -----------------------------------------------------------------
CATDDF_UExitCrypt ();
virtual ~CATDDF_UExitCrypt ();

/**
* Implements a function from an interface.
* @see CATIUExitCrypt#Code
*/
HRESULT Code (const void * iDecodedBuffer, size_t iDecodedLen, void ** oCodedBuffer, size_t * oCodedLen);

/**
* Implements a function from an interface.
* @see CATIUExitCrypt#Decode
*/
HRESULT Decode (const void * iCodedBuffer, size_t iCodedLen, void ** oDecodedBuffer, size_t * oDecodedLen);

private:
// The copy constructor and the equal operator must not be implemented
// -------------------------------------------------------------------
CATDDF_UExitCrypt (CATDDF_UExitCrypt &);
CATDDF_UExitCrypt& operator=(CATDDF_UExitCrypt&);
};

#endif

Note: You must update the dictionary before launching CATDMUUtility:

  • In the directory $Framework\CNext\code\dictionary, you'll find the dictionary file, e.g. NavigatorDataFlow.dic
  • Add the following line to this file: 
    CATUExitCrypt      CATIUExitCrypt      libCATDDFUserExit
    where libCATDDFUserExit is the library that contains the compiled form of
    CATDDF_UExitCrypt.cpp
    and CATDDF_UExitCrypt.h

 

Note: You must modify the Imakefile of CATDDFUserExit.m by adding SystemUUID in the  LINK_WITH statement.

Example:

# COPYRIGHT DASSAULT SYSTEMES 2002
#======================================================================
BUILT_OBJECT_TYPE=SHARED LIBRARY
LINK_WITH =
SystemUUID  
# System dependant variables
#
OS = AIX
#
OS = HP-UX
#
OS = IRIX
#
OS = SunOS
#
OS = Windows_NT