Compressing and encrypting a string
With Easy Compression Library you can easily compress/encrypt and decompress/decrypt a string.
Compressing/encrypting a string.
To compress and encrypt a string you need to call ECLCompressAndEncryptString function.
If the string should not be encrypted, the Password parameter is to be blank.
CompressionLevel specifies what compression algorithm and mode is used.
If the string should not be compressed, the CompressionLevel parameter is to be eclNone.
If you need to have data corruption verification code you should set bNoCRC parameter to False;
Decompressing/decrypting a string.
To decompress and decrypt a string you need to call ECLDecompressAndDecryptString.
Also you may want to know whether the string is encrypted.
Set bHexFormat parameter of ECLCompressAndEncryptString to True if you plan to access the compressed / encrypted string as null-terminated string (PChar). This is required if you store encrypted password to Registry for example.
By default compressed / encrypted string can contain some CHR(0) entrances and accessing the string with PChar() will not be correct.
The following example illustrates how to compress and encrypt a string and then decompress and decrypt it.
CompStr, DecompStr: string;
ECLCompressAndEncryptString('test', CompStr, 'Password', ppmFastest);
ECLDecompressAndDecryptString(CompStr, DecompStr, 'Password');