Wiki Home

Fox Crypto

(Updated: 2009.03.20 04:57:02 PM)
Namespace: VFP
Fox Crypto is a Visual FoxPro FLL library written by Albert Ballinger that wraps Wei Dai's public domain Crypto++ - a free C++ class library of cryptographic schemes.

Fox Crypto is exposes the following Cryto++ classes:
Fox Crypto Interface
Cryto++ ClassFoxCrypto Function
Base64Encoder
lcEncoded = Base64Encoder( tcBinary, tlInsertLineBreaks )
lnHandle = Base64EncoderCreate( tlInsertLineBreaks )
llSuccess = Base64EncoderDestroy( tnHandle )
lnSize = Base64EncoderPut( tnHandle, tcBinary )
llSuccess = Base64EncoderClose( tnHandle )
lnSize = Base64EncoderMaxRetrievable( tnHandle )
lcEncoded = Base64EncoderGet( tnHandle, tnSize )
Base64Decoder
lcBinary = Base64Decoder( tcEncoded )
lnHandle = Base64DecoderCreate()
llSuccess = Base64DecoderDestroy( tnHandle )
lnSize = Base64DecoderPut( tnHandle, tcEncoded )
llSuccess = Base64DecoderClose( tnHandle )
lnSize = Base64DecoderMaxRetrievable( tnHandle )
lcBinary = Base64DecoderGet( tnHandle, tnSize )
Gzip
lcGzipped = GzipEncoder( tcBinary, tnDeflateLevel )
lnHandle = GzipCreate( tnDeflateLevel )
llSuccess = GzipDestroy( tnHandle )
lnSize = GzipPut( tnHandle, tcBinary )
llSuccess = GzipClose( tnHandle )
lnSize = GzipMaxRetrievable( tnHandle )
lcGzipped = GzipGet( tnHandle, tnSize )
Gunzip
lcBinary = Gunzip( tcGzipped )
lnHandle = GunzipCreate()
llSuccess = GunzipDestroy( tnHandle )
lnSize = GunzipPut( tnHandle, tcGzipped )
llSuccess = GunzipClose( tnHandle )
lnSize = GunzipMaxRetrievable( tnHandle )
lcBinary = GunzipGet( tnHandle, tnSize )
HexEncoder
lcEncoded = HexEncoder( tcBinary, tlUpperCase )
lnHandle = HexEncoderCreate( tlUpperCase )
llSuccess = HexEncoderDestroy( tnHandle )
lnSize = HexEncoderPut( tnHandle, tcBinary )
llSuccess = HexEncoderClose( tnHandle )
lnSize = HexEncoderMaxRetrievable( tnHandle )
lcEncoded = HexEncoderGet( tnHandle, tnSize )
HexDecoder
lcBinary = HexDecoder( tcEncoded )
lnHandle = HexDecoderCreate()
llSuccess = HexDecoderDestroy( tnHandle )
lnSize = HexDecoderPut( tnHandle, tcEncoded )
llSuccess = HexDecoderClose( tnHandle )
lnSize = HexDecoderMaxRetrievable( tnHandle )
lcBinary = HexDecoderGet( tnHandle, tnSize )
ZlibCompressor
lcCompressed = ZlibCompressor( tcBinary, tnDeflateLevel )
lnHandle = ZlibCompressorCreate( tnDeflateLevel )
llSuccess = ZlibCompressorDestroy( tnHandle )
lnSize = ZlibCompressorPut( tnHandle, tcBinary )
llSuccess = ZlibCompressorClose( tnHandle )
lnSize = ZlibCompressorMaxRetrievable( tnHandle )
lcCompressed = ZlibCompressorGet( tnHandle, tnSize )
ZlibDecompressor
lcBinary = ZlibDecompressor( tcCompressed )
lnHandle = ZlibDecompressorCreate()
llSuccess = ZlibDecompressorDestroy( tnHandle )
lnSize = ZlibDecompressorPut( tnHandle, tcCompressed )
llSuccess = ZlibDecompressorClose( tnHandle )
lnSize = ZlibDecompressorMaxRetrievable( tnHandle )
lcBinary = ZlibDecompressorGet( tnHandle, tnSize )
CRC32
lcCode = CRC32( tcBinary )
lnHandle = CRC32Create()
llSuccess = CRC32Destroy( tnHandle )
lnSize = CRC32DigestSize()
lnSize = CRC32Update( tnHandle, tcBinary )
lcCode = CRC32Final( tnHandle )
MD5
lcCode = MD5( tcBinary )
lnHandle = MD5Create()
llSuccess = MD5Destroy( tnHandle )
lnSize = MD5DigestSize()
lnSize = MD5Update( tnHandle, tcBinary )
lcCode = MD5Final( tnHandle )

The URL's are no good anymore -- the domain is "for sale"
I have uploaded to my server -- don't know if it's the last one, but it works - source is included if someone wants to "take it up"
http://jassing.com/binaries/FoxCrypto.zip

The latest version of Fox Crypto can be found at http://www.connectthenet.com/foxpro/FoxCrypto.fll.

Some simple VFP test programs can be found at http://www.connectthenet.com/foxpro/FoxCryptoTest.zip. Please note that the Put and Get functions can be called iteratively.

The Fox Crypto source code and Visual C++ 6.0 project can be found at http://www.connectthenet.com/foxpro/FoxCryptoSource.zip. The source should be unzipped to a Fox Crypto subdirectory under a directory containing the Crypto++ source.

* zlib_example
*
* Example of using the Zlib classes of FoxCrypto with
* a continuous status update.  This technique can be
* used with some sort of progress bar control.
*
* Zlib compression is guaranteed to return a string
* that is of equal or lesser length than the original.
* This makes Zlib compression a good candidate for
* compressing Memo field data.  Decompression follows
* analogous steps.

* This is the way to do this in one function call:
* SET LIBRARY TO FoxCrypto
* lcCompressed = ZlibCompressor( tcBinary, tnDeflateLevel )

#DEFINE BLOCK_SIZE	1024

DECLARE Sleep IN win32api AS Sleep INTEGER tnMilliseconds

SET LIBRARY TO FoxCrypto

LOCAL lnHandle, lcInString, lcOutString

lcInString = REPLICATE("Test String...", 10000)

LOCAL lnInStringLength, lnOutStringLength, lnProcessSize

lnInStringLength = LEN(lcInString)
lnProcessSize = 0

LOCAL i, lnHandle, lnSize

* create a ZlibCompressor object and store its handle
* 9 is the highest possible compression level, and the slowest
lnHandle = ZlibCompressorCreate(9)

IF lnHandle > 0
  FOR i = 1 TO lnInStringLength STEP BLOCK_SIZE
    * add a block of data to the compressor
    lnProcessSize = lnProcessSize + ;
      ZlibCompressorPut(lnHandle, SUBSTR(lcInString, i, BLOCK_SIZE))
    * give a status update
    SET MESSAGE TO "ZlibCompressor " + ;
      TRANSFORM(lnProcessSize) + ;
      " of " + ;
      TRANSFORM(lnInStringLength) + ;
      ", " + ;
      TRANSFORM(lnProcessSize / lnInStringLength * 100, "999.99") + "%"
    Sleep(200) && slow it down so we can see the messages
  ENDFOR
  * the compressor must be closed before the compressed string
  * is read back
  IF !ZlibCompressorClose(lnHandle)
    DO ReportError WITH ;
      "ZlibCompressor object close failed.", lnHandle
  ELSE
    * we will read back the whole string at once, we could
    * read it back in blocks
    lnSize = ZlibCompressorMaxRetrievable(lnHandle)
    IF lnSize < 1
      DO ReportError WITH ;
        "ZlibCompressor object has no compressed data to read.", lnHandle
    ELSE
      lcOutString = ZlibCompressorGet(lnHandle, lnSize)
      * destroy the compressor object
      IF !ZlibCompressorDestroy(lnHandle)
        DO ReportError WITH ;
          "ZlibCompressor object destruction failed."
      ELSE
        * give the final status
        SET MESSAGE TO "ZlibCompressor " + ;
          TRANSFORM(lnInStringLength) + ;
          " of " + ;
          TRANSFORM(LEN(lcOutString)) + ;
          ", " + ;
          TRANSFORM(LEN(lcOutString) / lnInStringLength * 100, ;
          "999.99") + "%"
      ENDIF
    ENDIF
  ENDIF
ELSE
  DO ReportError WITH ;
    "ZlibCompressor object creation failed."
ENDIF

PROCEDURE ReportError ( tcMessage, tnHandle )
  SET MESSAGE TO
  IF PCOUNT() > 1
    * try to clean up
    ZlibCompressorDestroy(tnHandle)
  ENDIF
  ERROR(tcMessage)
ENDPROC

Albert - is there a reason you chose to use an FLL to do this instead of a DLL? It's a lot easier to setup the interface to the methods. I've got two examples of VC++ projects that expose C++ methods as callable functions in VFP over on my website. df
It is easier for the C++ developer, but is harder on the VFP developer. You have to do all of the calls to DEFINE DLL and the strings passed would require length parameters. Additionally, I don't know how to return a string of unknown (in VFP) length from a DLL function call. Albert Ballinger
Albert,

I really appreciate the effort, but the documentation (above) is less than adequate and the samples don't help because they are rather esoteric.

For example, in the above HTML table there is a GzipEncoder function that doesn't exist within the FLL.

Also, I'm seeing with GZip that there is no difference in size from one level of deflation to another. I'm using DBFs that are 11 MB. Yet they all come out the same size.
Category Code Samples Category Encryption