If you use Cryptor from XiTech for encryption in VFP, you may be aware that its FLL is sensitive to the version of VFP you're using. For example, C40Fox80.FLL is for VFP 8, C40Fox70.FLL is for VFP 7, etc. Although Cryptor 5 has been available for some time, I haven't bothered to upgrade because version 4 does everything I need it to. Also, there are some installation issues with Cryptor 5 on Vista, since it's now a COM object, while version 4 doesn't need registration. One problem with version 4, though, is that it doesn't come with an FLL for VFP 9.
Fortunately, you don't need one. Cryptor comes with a DLL, XICrCore.DLL, that contains functions providing Cryptor features. I use a class called SFCryptor that's a wrapper for the DLL. You can download it from the Technical Papers page of my Web site.
Here are the declarations for these functions:
lcDLL = fullpath('XICrCore.dll', addbs(.cCryptorPath))
declare integer CRYIni_Initialize in (lcDLL) ;
integer LoadMode
declare integer CRYIni_InitializeEx in (lcDLL) ;
integer dwLoadMode, integer hModule, string strExclusionList
declare integer CRYIni_UnInitialize in (lcDLL)
declare integer CRYUtl_EncodeString in (lcDLL) ;
string strSrc, string @ strDest, integer dwLength, ;
string strPassword, integer dwMethod
declare integer CRYUtl_DecodeString in (lcDLL) ;
string strSrc, string @ strDest, integer dwLength, ;
string strPassword, integer dwMethod
declare string CRYUtl_GetErrorMessage in (lcDLL) ;
integer errorCode
declare integer CRYUtl_Encode in (lcDLL) ;
string strFilename, string strPassword, string strBackupExt, ;
integer bKeepBackup, integer dwMethod
declare integer CRYUtl_Decode in (lcDLL) ;
string strFilename, string strPassword, string strBackupExt, ;
integer bKeepBackup, integer dwMethod
declare integer CRYMan_Register in (lcDLL) ;
string strFilename, string strPassword, integer dwFlags, ;
integer dwMethod
declare integer CRYMan_Unregister in (lcDLL) ;
string strFilename
declare integer CRYMan_List in (lcDLL) ;
integer dwFunction, string @ strFilename, integer @ pdwFlags, ;
integer @ pdwMethod, integer @ pdwCountThis code initializes Cryptor:
#define CRYPTOR_ERR_SUCCESS 0x00000000
#define CRYPTOR_ERR_ALREADY_INITIALIZED 0xFFFFFF02 - 0x100000000
if version(2) = 0
declare integer GetModuleHandle in Win32API string ModuleName
lnHookModule = GetModuleHandle('VFP' + ;
left(transform(version(5)), 1) + 'R.DLL')
if lnHookModule <> 0
lnStatus = CRYIni_InitializeEx(2, lnHookModule, ';')
else
lnStatus = -1
endif lnHookModule <> 0
else
lnStatus = CRYIni_InitializeEx(2, 0, ';')
endif version(2) = 0
if inlist(lnStatus, CRYPTOR_ERR_SUCCESS, ;
CRYPTOR_ERR_ALREADY_INITIALIZED)
llInitialized = .T.
else
lcErrorMessage = 'Could not initialize Cryptor: status ' + ;
'code ' + transform(lnStatus)
llInitialized = .F.
endif inlist(lnStatus ...
This code registers, unregisters, encrypts, or decrypts a file; pass it the filename, password, encryption method, and "register" to register the file, "unregister" to unregister it, "encrypt" to encrypt it, or "decrypt" to decrypt it. Error handling code was removed for brevity.
lparameters tcFileName, ;
tcPassword, ;
tnMethod, ;
tcProcess
local laFiles[1], ;
lnFiles, ;
lcPath, ;
lnI, ;
lcFile, ;
lnStatus, ;
llReturn
* Get the file to process. Use ADIR() because we may a file skeleton
* like SOMETHING.*.
lnFiles = adir(laFiles, tcFileName)
* Try to process the file(s).
lcPath = addbs(justpath(tcFileName))
for lnI = 1 to lnFiles
lcFile = lower(lcPath + laFiles[lnI, 1])
do case
case tcProcess = 'encrypt'
lnStatus = CRYUtl_Encode(lcFile, tcPassword, .NULL., 0, ;
tnMethod)
case tcProcess = 'decrypt'
lnStatus = CRYUtl_Decode(lcFile, tcPassword, .NULL., 0, ;
tnMethod)
case tcProcess = 'register'
lnStatus = CRYMan_Register(lcFile, tcPassword, 0, tnMethod)
case tcProcess = 'unregister'
lnStatus = CRYMan_Unregister(lcFile)
endcase
llReturn = lnStatus = CRYPTOR_ERR_SUCCESS
if not llReturn
lcErrorMessage = 'Could not ' + tcProcess + ' ' + lcFile + ;
': ' + CRYUtl_GetErrorMessage(lnStatus)
exit
endif not llReturn
next lnI
return llReturn