如何在使用delphi的lockbox 3中使用AES-256加密 [英] How to use AES-256 encryption in lockbox 3 using delphi

查看:695
本文介绍了如何在使用delphi的lockbox 3中使用AES-256加密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一周前我已经下载了Lockbox3,我无法使用它,我无法理解演示,因为它很复杂,我无法从中获得我想要的代码,我想使用lockbox 3 AES-256加密来加密Delphi中的字符串。

解决方案

方法和属性名称几乎全部说明。这是一种加密字符串然后再次解密的方法,假设您已经在设计时设置了编解码器属性,这也是自描述的。

  procedure TForm1.actEncryptStringExecute(Sender:TObject); 
var
Plaintext,sReconstructedPlaintext:string;
base64Ciphertext:ansistring;
begin
sPlainText:=我喜欢LockBox 3!;
如果不是InputQuery('Plaintext','输入要加密的明文(UTF-16LE编码):',sPlainText)然后退出;
codec.EncryptString(sPlaintext,base64Ciphertext);
ShowMessageFmt('编码密文的base64编码为'#13#10 +'%s',[base64Ciphertext]);
codec.DecryptString(sReconstructedPlaintext,base64Ciphertext);
ShowMessageFmt('解密后,将其解密回%s',[sReconstructedPlaintext])
end;

再看看演示程序。加密按钮的处理程序加密文件而不是字符串。除此之外,如果您剥离装饰绒毛,如将信息发布到备忘录,并处理异常,如果用户指定了不存在的文件,它非常简单 - 它基本上归结为一行...

  codecMainDemo.EncryptFile(edtPlaintextFile.Text,edtCiphertextFile.Text); 

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



演示显示安装程序:


  1. 在您的表单上放置一个TCryptographicLibrary组件;

  2. 将TCodec组件放在表单上;

  3. 选择您喜欢的密码

  4. 选择您喜欢的链接模式;和

  5. 设置密码

和Bob的叔叔!



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


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.

解决方案

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:

  1. Put an TCryptographicLibrary component on your form;
  2. Put a TCodec component on your form;
  3. Select your prefered cipher
  4. Select your prefered chaining mode; and
  5. Set the password

and Bob's your uncle!

Let me know if you have any problems.

这篇关于如何在使用delphi的lockbox 3中使用AES-256加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆