J'essaie lockbox3 avec Delphi XE10. Je souhaite chiffrer la chaîne d'entrée d'un utilisateur et la comparer à une valeur à vérifier. mais chaque fois que la même chaîne d'entrée donne un résultat chiffré différent. Quelle est ma faute, s'il vous plait?Lockbox3 encryptstring: la même chaîne donne un résultat chiffré différent
ici l'exemple de code qui donne cette erreur
<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>
Crypto vous faut vraiment avoir une compréhension de base. Sans cela, vous risquez de produire du code non sécurisé. –