Delphi 加密解密

本文介绍了一个使用Delphi实现的加密与解密过程示例。通过TDCP_blockcipher组件采用CFB模式对字符串进行加密,并使用Base64进行编码与解码。示例包括了文件读写操作及简单的用户界面交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

procedure TForm3.FormCreate(Sender: TObject);
var
  RegI: 
String;
  F: TextFile;
  Cipher: TDCP_blockcipher;
  S: 
string;
begin
  AssignFile(F, GetSysDir
+'test.txt');
  Reset(F);
  Readln(F,S);
  CloseFile(F);
  Cipher:
= TDCP_blockcipher(DCP_cast2561);
  Cipher.InitStr(
'Key');
  S:= B64Decode(S);
  Cipher.DecryptCFB(S[
1],S[1],Length(S));
  Cipher.Reset;
  Cipher.Burn;
  ShowMessage(S);
end;

 

 

procedure TForm3.cxButton2Click(Sender: TObject);
var
  RegI: 
String;
  F: TextFile;
  Cipher: TDCP_blockcipher;
  S: 
string;
begin
  RegI :
= 'This is a book.';
  Cipher:= TDCP_blockcipher(DCP_cast2561);
  Cipher.InitStr(
'Key');
  Cipher.EncryptCFB(RegI[1],RegI[1],Length(RegI));
  S :
= B64Encode(RegI);
  Cipher.Reset;
  Cipher.Burn;
  AssignFile(F, GetSysDir
+'test.txt');
  Rewrite(F);
  Writeln(F,S);
  CloseFile(F);
end;

dcpcrypt1.31

 

function TForm3.EnC(S:string):String;
begin
  DCP_cast2561.InitStr(
'HZQ-1982.1983');
  DCP_cast2561.EncryptCFB(S[1],S[1],Length(S));
  S :
= B64Encode(S);
  DCP_cast2561.Reset;
  DCP_cast2561.Burn;
  Result :
= S;
end;
function TForm3.DeC(S:string):String;
begin
  DCP_cast2561.InitStr(
'HZQ-1982.1983');
  S := B64Decode(S);
  DCP_cast2561.DecryptCFB(S[
1],S[1],Length(S));
  DCP_cast2561.Reset;
  DCP_cast2561.Burn;
  Result :
= S;
end;

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值