var
Key: TTEAKey;
EncryptedText: RawByteString;
S: String;
begin
// Use default key
Key := TEADefaultKey; // - same as TEADeriveKey('', nil);
// Encrypt some text with the default key
// (meaning "encrypt some text with empty password")
EncryptedText := TEAEncrypt(Key, 'clear text');
// EncryptedText contains encrypted RAW bytes
// Do not output EncryptedText to any place which expects human-readable text
// There is no much meaning in wiping key from memory, as it is always present anyway
// Debug output
// Encrypted text is RAW bytes, so we need to convert it to something readable
// Encrypted value will be the same for the same text
Edit1.Text := HexEncodeString(EncryptedText);
// _____________________________________________
// Use default key
Key := TEADefaultKey; // - same as TEADeriveKey('', nil);
// Decrypt text back
// Use encrypted RAW binary, not the hex-converted text
S := TEADecrypt(Key, EncryptedText);
// There is no much meaning in wiping key from memory, as it is always present anyway
// Wipe also all data
SecureFree(EncryptedText);
// Now S = 'clear text'
// Call SecureFree for all data once you have finished working with it
SecureFree(S);
end;
|