Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   LockBox 3 String verschlüsseln. (https://www.delphipraxis.net/185039-lockbox-3-string-verschluesseln.html)

Kostas 10. Mai 2015 18:08

LockBox 3 String verschlüsseln.
 
Hallo Zusammen,

ich habe die aktuelle Version von LockBox3 Version 3.5.0 in Delphi XE7 installiert
und mich auf der Such nach der Doku gemacht. Anscheinend gibt es keine oder gut versteckt.
Es geht darum einfach ein String zu ver- und entschlüsseln.

Gefunden habe ich das, aber es funktioniert nicht.
Ich bekomme eine Fehlermeldung: TSimpleCodec.Begin_EncryptMemory - Algorytms not set.
Was sind das für Werte für StreamCipherId, BlockCipherId und ChainModeId?

Delphi-Quellcode:
function EncryptText_AES_128(input: string; password: string): string;
var
  Codec: TCodec;
  CipherText: String;
  Encoding:TEncoding;
begin
  Codec := TCodec.Create(nil);
  try
    Codec.CryptoLibrary := TCryptographicLibrary.Create(Codec);
    //
    Codec.StreamCipherId := 'native.StreamToBlock';
    Codec.BlockCipherId := Format('native.AES-%d', [128]);
    Codec.ChainModeId := 'dunit.ECB';
    //
    Codec.Password := Password;
    Codec.EncryptString(input, CipherText, Encoding.ANSI);
    //
    Result := string(CipherText);
  finally
    Codec.Free;
  end;
end;
Hat jemand eine Idee?

Gruß Kostas

Klaus01 10. Mai 2015 18:22

AW: LockBox 3 String verschlüsseln.
 
Guten Abend,

vielleicht hilft Dir dieser Thread:
http://stackoverflow.com/questions/1...ory-wrong-mode

Grüße
Klaus

Kostas 10. Mai 2015 20:56

AW: LockBox 3 String verschlüsseln.
 
Tausend Dank Klaus,

das war der richtige Hinweis. So funktioniert es einwandfrei.
Der Link zur Hilfe funkt derzeit nicht.


Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var FLibrary : TCryptographicLibrary;
    FCodec : TCodec;
    plain,astr,dec : string;
    FEncoding : TEncoding;
begin
  plain := 'The plain text';

  FLibrary := TCryptographicLibrary.Create(Self);
  FCodec := TCodec.Create(Self);
  try
    FCodec.CryptoLibrary := FLibrary;
    FCodec.StreamCipherId := 'native.StreamToBlock';
    FCodec.BlockCipherId := 'native.AES-256';
    FCodec.ChainModeId := 'native.ECB';
    FCodec.Password := 'password';


    FCodec.EncryptString(plain, astr, FEncoding.ANSI);
    FCodec.DecryptString(dec, astr, FEncoding.ANSI);

  finally
    FCodec.Free;
    FLibrary.Free;
  end;

  Edit1.Text := astr;
  Edit2.Text := dec;
end;

Gruß Kostas


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:39 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz