如何使用Delphi在密码箱3中使用AES-256加密

Ker*_*ugi 1 delphi encryption turbopower lockbox-3

我大约一周前已经下载了Lockbox3,但我无法使用它,并且我无法理解该演示,因为它很复杂,无法从中获取所需的代码,我想使用Lockbox 3 AES- 256个加密可在Delphi中加密字符串。

Sea*_*kin 5

方法和属性名称几乎说明了一切。假设您已在设计时设置了编解码器属性,这也是一种自描述的方法,该方法先对字符串进行加密,然后再将其解密。

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;
Run Code Online (Sandbox Code Playgroud)

再看一下演示程序。“加密”按钮的处理程序对文件而不是字符串进行加密。除此之外,如果您剥离装饰性的绒毛,例如将信息发布到备忘录中,并且如果用户指定了不存在的文件则处理异常,则它的操作非常简单-它基本上可以简化为一行...

codecMainDemo.EncryptFile( edtPlaintextFile.Text, edtCiphertextFile.Text );
Run Code Online (Sandbox Code Playgroud)

要加密字符串,请调用EncryptString()。要加密文件,请调用EncryptFile()。

该演示显示了设置,例如:

  1. 在您的表单上放置一个TCryptographicLibrary组件;
  2. 在您的窗体上放置一个TCodec组件;
  3. 选择您喜欢的密码
  4. 选择您喜欢的链接模式;和
  5. 设定密码

而鲍勃是你的叔叔!

如果您有任何问题,请告诉我。