LockBox  官  方  网  站:http://lockbox.seanbdurkin.id.au/HomePage

LockBox的Github 网址:https://github.com/SeanBDurkin/tplockbox

LockBox 3.7.0  下   载:https://github.com/SeanBDurkin/tplockbox/archive/master.zip

LockBox3.7.0的安装:

1,解压缩下载的LockBox3.7.0压缩包,把压缩包内所有东西放入你想要放的目录中,我放到了:“C:\DelphiLib\LockBox3.7.0”中。

2,把“C:\DelphiLib\LockBox3.7.0\run”加入你的Delphi的"library"中。点击菜单“Tools”->"Options",在随手弹出的对话框中,选择左侧的“Delphi Options”->"Library",随后点击右侧“Library path”下面右侧的按钮,随后加入上面的目录。注意:这个目录是我自己存放LockBox3.7.0的地方,你应该换成你自己存放LockBox3.7.0的对应目录!

3,编译和安装LockBox3.7.0。

A,打开你使用的Delphi对应的运行时工程目录,我使用Delphi XE8,对应的目录是“C:\DelphiLib\LockBox3.7.0\packages\XE8”,随后把工程组文件直接拖入Delphi XE8里面。

B,鼠标右键工程组,随后点击右键菜单“Build ALL”。

注意:如果这个时候出错了,查看出错的关键字,我第一次编译时候出错了,这个关键字不对,随后我添加上面的路径到library里面后,再次编译,发现关键字被修改错误了,改正成Delphi正确的关键字就可以了。下图我列举了我当时出现的错误状况,就是关键字被篡改了!!

C,安装LockBox,鼠标右键“dclTP_LockBox3_XE8.bpl”,点击“install”,如果一切顺利,你应该安装上了。

到现在,我们就已经成功安装了LockBox3.7.0了,如果你不去修改先前版本LockBox的代码,直接使用没有问题,如果你想修改先前版本LockBox的代码,一大堆问题,先看看问题,随后我告诉你如何解决!!

错误截图:

解决方法:

1,查看“C:\DelphiLib\LockBox3.7.0\work-products\ephemeral\dcu\XE8\Win32”目录中DCU文件名称,发现都是“TPLB3.Codec.dcu”这样的格式了,和Delphi目前最新的单元名称是不是一样?

2,把所有有错误的单元文件名修改成“TPLB3.”+原来下划线后面的单元文件名,例如:原单元文件名“uTPLb_Signatory”,修改成“TPLB3.Signatory”,马上错误消失,一直按照这样方法修改所有错误,随后编译,完全正确!

加密解密演示例子:

完整例子下载:http://download.csdn.net/detail/sunylat/9728033

unit Unit1;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls; type
TForm2 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
clearLogBtn: TButton;
logMemo: TMemo;
Splitter1: TSplitter;
Panel3: TPanel;
Button2: TButton;
Memo1: TMemo;
Button1: TButton;
Memo2: TMemo;
procedure clearLogBtnClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations } // 加密字符串
procedure EncryptString(keyStr, Plaintext: string; var CipherText: String); // 解密字符串
procedure DecryptString(keyStr: string; var Plaintext: string;
CipherText: String); public
{ Public declarations }
procedure MyLog(tempLog: string); // log方法
end; const
EncryptKey = 'lockBoxKey'; // 测试用的加密解密key,你可以换成任意你想用的key var
Form2: TForm2; logInfo: string; // log信息 implementation {$R *.dfm} uses
TPLB3.Signatory, TPLB3.Codec, TPLB3.BaseNonVisualComponent,
TPLB3.CryptographicLibrary, TPLB3.Constants; // 加密字符串
procedure TForm2.EncryptString(keyStr, Plaintext: string;
var CipherText: String);
var
Codec2: TCodec;
CryptographicLibrary2: TCryptographicLibrary;
begin
try
Codec2 := TCodec.Create(nil);
CryptographicLibrary2 := TCryptographicLibrary.Create(nil);
Codec2.CryptoLibrary := CryptographicLibrary2;
// 这是动态创建对象能够工作的关键
Codec2.StreamCipherId := TPLB3.Constants.BlockCipher_ProgId; Codec2.BlockCipherId := TPLB3.Constants.DES_ProgId;
Codec2.ChainModeId := TPLB3.Constants.ECB_ProgId; // 设置密码
Codec2.Password := Trim(keyStr); // 加密字符串
Codec2.EncryptString(Plaintext, CipherText, TEncoding.Default); finally
Codec2.Free;
CryptographicLibrary2.Free;
end;
end; // 解密字符串
procedure TForm2.DecryptString(keyStr: string; var Plaintext: string;
CipherText: String);
var
Codec2: TCodec;
CryptographicLibrary2: TCryptographicLibrary;
begin
try
Codec2 := TCodec.Create(nil);
CryptographicLibrary2 := TCryptographicLibrary.Create(nil);
Codec2.CryptoLibrary := CryptographicLibrary2;
// 这是动态创建对象能够工作的关键
Codec2.StreamCipherId := TPLB3.Constants.BlockCipher_ProgId; Codec2.BlockCipherId := TPLB3.Constants.DES_ProgId;
Codec2.ChainModeId := TPLB3.Constants.ECB_ProgId; // 设置密码
Codec2.Password := Trim(keyStr); // 加密字符串
Codec2.DecryptString(Plaintext, CipherText, TEncoding.Default); finally
Codec2.Free;
CryptographicLibrary2.Free;
end;
end; procedure TForm2.Button1Click(Sender: TObject);
var
Plaintext: string; // 未加密信息变量
CipherText: string; // 加密后信息变量
begin
if Trim(logMemo.Text) <> '' then
begin
// 得到解密内容
CipherText := Trim(logMemo.Text); // 解密
self.DecryptString(EncryptKey, Plaintext, CipherText); // 显示解密内容
Memo2.Text := Plaintext; if Trim(Memo1.Text) <> '' then
begin
if Trim(Memo1.Text) = Trim(Memo2.Text) then
begin
showmessage('解密完全正确!!');
end
else
begin
showmessage('解密结果和加密前的内容不一致!!!');
end; end; end
else
begin
showmessage('对不起,要解密内容不能为空!');
end; end; procedure TForm2.Button2Click(Sender: TObject);
var
Plaintext: string; // 未加密信息变量
CipherText: string; // 加密后信息变量
begin // 要加密信息
Plaintext := Trim(Memo1.Text); if Plaintext = '' then
begin
showmessage('对不起,要加密内容不能为空!');
end
else
begin
// 加密
self.EncryptString(EncryptKey, Plaintext, CipherText); // 显示加密信息
logMemo.Text := CipherText;
end; end; procedure TForm2.clearLogBtnClick(Sender: TObject);
begin
logMemo.Clear;
end; procedure TForm2.FormCreate(Sender: TObject);
begin end; // log方法
procedure TForm2.MyLog(tempLog: string);
var
temp: string;
oldLog: string;
begin
if Trim(tempLog) <> '' then
begin oldLog := Trim(logMemo.Text);
logMemo.Clear; temp := FormatDateTime('yyyy-mm-dd hh:mm:ss', now) + ' ' + Trim(tempLog);
if oldLog = '' then
begin
logMemo.Lines.Add(temp);
logMemo.Lines.Add('');
end
else
begin
logMemo.Lines.Add(temp);
logMemo.Lines.Add('');
logMemo.Lines.Add(oldLog);
end; end; end; end.

最新文章

  1. P2V之后的磁盘扩容新思路
  2. select,poll,epoll区别
  3. Python 装饰器学习
  4. 小tip:CSS vw让overflow:auto页面滚动条出现时不跳动
  5. 安卓使用pull解析器解析XML文件
  6. BLE-NRF51822教程-RSSI获取
  7. sap mm_1
  8. SpringSecurityOauth RCE (CVE-2016-4977) 分析与复现
  9. VUE 创建element项目
  10. JavaSE基础知识(5)—面向对象(对象数组和对象关联)
  11. Python——教你画朵太阳花
  12. Django基础学习之Cookie 和 Sessions 应用
  13. Oracle Enterprise Linux 6.4 下配置vncserver
  14. C# 异常语句 跳转语句 while循环 穷举法 迭代法
  15. [Jobdu] 题目1528:最长回文子串
  16. RTX——第9章 任务运行在特权级或非特权级模式
  17. xdebug常用配置
  18. python3之环境搭建以及基础语法
  19. Python3 函数return
  20. Trie(前缀树/字典树)及其应用

热门文章

  1. ORA-20000 ORU-10027 buffer overflow limit of 2000 bytes
  2. 深入理解javascript中实现面向对象编程方法
  3. PowerDesigner生成Oracle数据库时,表名会带引号问题
  4. Unity3D&ndash;RectTransfrom 记录笔记
  5. Angular--$http服务
  6. LAMP简易安装
  7. JavaScript中字符串去掉特殊字符和转义字符
  8. 跨服务器的session共享
  9. LintCode StrStr
  10. Laravel框架数据库CURD操作、连贯操作使用方法