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

2939

被折叠的 条评论
为什么被折叠?



