I've downloaded Lockbox3 about a week ago and i can't use it, and i couldn't understand the demo because it's complex i couldn't get the codes i want from it, I'd like to use lockbox 3 AES-256 encryption to encrypt strings in Delphi.
-
4What are you trying to do, specifically? What have tried to make this work? What error message(s) did you receive? You are unlikely to get votes or a focused answer if you don't ask a very clear, focused question. You might want to read the faq linked above. – Argalatyr Feb 26 '12 at 01:44
2 Answers
The method and property names pretty much say it all. Here is a method which encrypts a string and then decrypts it back again, assuming you've setup the codec properties at design time, which are also self-describing.
procedure TForm1.actEncryptStringExecute( Sender: TObject );
var
Plaintext, sReconstructedPlaintext: string;
base64Ciphertext: ansistring;
begin
sPlainText := 'I love LockBox 3!';
if not InputQuery( 'Plaintext', 'Enter plaintext that you want to encrypt (UTF-16LE encoding):', sPlainText) then exit;
codec.EncryptString( sPlaintext, base64Ciphertext);
ShowMessageFmt('The base64 encoding of the encoded ciphertext is'#13#10+'%s',[base64Ciphertext]);
codec.DecryptString( sReconstructedPlaintext, base64Ciphertext);
ShowMessageFmt('After decryption, this decrypts back to %s',[sReconstructedPlaintext])
end;
Have another look at the demo program. The handler for Encrypt button, encrypts a file instead of a string. That aside, if you strip away the decorative fluff, like posting information to a memo, and handling exceptions if the user specified a non-existant file, its increddibly simple - it basically boils down to one line...
codecMainDemo.EncryptFile( edtPlaintextFile.Text, edtCiphertextFile.Text );
To encrypt a string, you call EncryptString(). To encrypt a file you call EncryptFile().
The demo shows the setup, to wit:
- Put an TCryptographicLibrary component on your form;
- Put a TCodec component on your form;
- Select your prefered cipher
- Select your prefered chaining mode; and
- Set the password
and Bob's your uncle!
Let me know if you have any problems.

- 12,659
- 1
- 36
- 65
-
I have just install these components into XE6, EncryptString needs as third parameter some TEncoding from Sysutils, what shall I do with that? – Vlastimil Burián Sep 18 '16 at 19:45
-
It depends on what string encoding do you want. UTF-8? UTF-16LE? or something else. – Sean B. Durkin Sep 19 '16 at 07:01
-
normal ASCII string, I have no idea on what to do with it, thank you beforehand – Vlastimil Burián Sep 19 '16 at 07:22
-
What is a "normal ASCII string"? Maybe you mean UTF-8? - then use TEncoding.UTF8 . – Sean B. Durkin Sep 19 '16 at 07:25
Sean Your example has at least one error if not more:
var
Plaintext, sReconstructedPlaintext: string;
base64Ciphertext: ansistring;
Plaintext should be sPLaintext.
Plus Delphi Sydney compiler flags an error 'Not enough actual parameters' on codec.EncryptString( sPlaintext, base64Ciphertext);
I think that uncle bob was having an off day. This is a great library but unfortunately it is let down by poor documentation. I have ploughed my way through the relevant units in order to make some progress but it is a shame that I have to do this in order to assess whether I want to use it - I am writing a textbook for the school's market.