我尝试使用 Delphi XE10 的 lockbox3。我想加密用户的输入字符串并将其与验证值进行比较。但每次相同的输入字符串都会给出不同的加密结果。请问我的错是什么?
这里给出了这个错误的示例代码
<UNIT CODE START>
unit Unit21;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, TPLB3.Codec, TPLB3.BaseNonVisualComponent, TPLB3.CryptographicLibrary,
Vcl.StdCtrls;
type
TForm21 = class(TForm)
Button1: TButton;
CryptographicLibrary1: TCryptographicLibrary;
Codec1: TCodec;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form21: TForm21;
implementation
{$R *.dfm}
procedure TForm21.Button1Click(Sender: TObject);
var s0,s1 : string;
begin
codec1.Password := 'ou[asdl[kn';
s0 := 'asdfghjkl';
codec1.EncryptString(s0,s1);
label1.caption := s1;
end;
end.
<UNIT CODE END>
<FORM CODE START>
object Form21: TForm21
Left = 0
Top = 0
Caption = 'Form21'
ClientHeight = 299
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 168
Top = 72
Width = 31
Height = 13
Caption = 'Label1'
end
object Button1: TButton
Left = 32
Top = 72
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object CryptographicLibrary1: TCryptographicLibrary
Left = 192
Top = 136
end
object Codec1: TCodec
AsymetricKeySizeInBits = 512
AdvancedOptions2 = []
CryptoLibrary = CryptographicLibrary1
Left = 200
Top = 192
StreamCipherId = 'native.StreamToBlock'
BlockCipherId = 'native.AES-256'
ChainId = 'native.CBC'
end
end
<FORM CODE END>