![]() ![]() ![]() |
Getting encryption state of a memory buffer
To know whether the buffer is encrypted, use IsECLBufferEncrypted function.
The following example illustrates how to check whether the data in buffer is encrypted and handle wrong password input.
Example:
var
SrcBuf, CompBuf, DecompBuf: PChar;
SrcSize, CompSize, DecompSize: integer;
s: string;
begin
{ source data }
s := 'test-test';
{ pointer to source data }
SrcBuf := PChar(s);
{ size of source data }
SrcSize := Length(s)+1;
{ compress and encrypt source buffer to destination buffer }
ECLCompressAndEncryptBuffer(SrcBuf, SrcSize, CompBuf, CompSize, 'Password', ppmFastest);
{ is data encrypted? }
if (IsECLBufferEncrypted(CompBuf)) then
begin
{ try to decompress and decrypt buffer with wrong password}
if (not ECLDecompressAndDecryptBuffer(CompBuf, CompSize, DecompBuf, DecompSize, 'Wrong Password')) then
ShowMessage('Decrypting with wrong password is failed!');
{ try to decompress and decrypt buffer with right password}
if (not ECLDecompressAndDecryptBuffer(CompBuf, CompSize, DecompBuf, DecompSize, 'Password')) then
ShowMessage('Decrypting with right password is failed!');
end
else
{ data is not encrypted, simply decompress the buffer }
ECLDecompressAndDecryptBuffer(CompBuf, CompSize, DecompBuf, DecompSize);
{ display decompressed/decrypted data }
ShowMessage('Decrypted and decompressed data: '+DecompBuf);
end;