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
s := 'test-test';
SrcBuf := PChar(s);
SrcSize := Length(s)+1;
ECLCompressAndEncryptBuffer(SrcBuf, SrcSize, CompBuf, CompSize, 'Password', ppmFastest);
if (IsECLBufferEncrypted(CompBuf)) then
begin
if (not ECLDecompressAndDecryptBuffer(CompBuf, CompSize, DecompBuf, DecompSize, 'Wrong Password')) then
ShowMessage('Decrypting with wrong password is failed!');
if (not ECLDecompressAndDecryptBuffer(CompBuf, CompSize, DecompBuf, DecompSize, 'Password')) then
ShowMessage('Decrypting with right password is failed!');
end
else
ECLDecompressAndDecryptBuffer(CompBuf, CompSize, DecompBuf, DecompSize);
ShowMessage('Decrypted and decompressed data: '+DecompBuf);
end;
|