![]() |
Speicherblock mit Rjindael verschlüsseln/entschlüsseln
Hallo,
unter .Net verwendet man die Klassen aus dem Namespace System.Security.Cryptography. Hier mal zwei Beispiele zum Ver-/Entschlüsseln eines Speicherblocks mit Rijndael:
Delphi-Quellcode:
Gruß
type
Bytes = array of Byte; function Encrypt(Buffer, Key, IV: Bytes): Bytes; var Encryptor: ICryptoTransform; ST: MemoryStream; Encrypt: CryptoStream; FAlgorythm: RijndaelManaged; begin // Vernünftige Argumente? if (IV = '') or (Key = '') then begin Result := Buffer; Exit; end; // Vorbereiten FAlgorythm := RijndaelManaged.Create; FAlgorythm.IV := IV; FAlgorythm.Key := Key; FAlgorythm.Mode := CipherMode.CBC; FAlgorythm.Padding := PaddingMode.Zeros; Encryptor := FAlgorythm.CreateEncryptor; // Stream erstellen ST := MemoryStream.Create; Encrypt := CryptoStream.Create(ST, Encryptor, CryptoStreamMode.Write); // Speicher in Stream schreiben Encrypt.Write(Buffer, 0, Length(Buffer)); Encrypt.FlushFinalBlock; // Ergebnis abgreifen Result := ST.ToArray; end; function Decrypt(Buffer, Key, IV: Bytes): Bytes; var Decryptor: ICryptoTransform; ST: MemoryStream; Decrypt: CryptoStream; FAlgorythm: RijndaelManaged; begin if (IV = '') or (Key = '') then begin Result := Buffer; Exit; end; FAlgorythm := RijndaelManaged.Create; FAlgorythm.IV := IV; FAlgorythm.Key := Key; FAlgorythm.Mode := CipherMode.CBC; FAlgorythm.Padding := PaddingMode.Zeros; Decryptor := FAlgorythm.CreateDecryptor; ST := MemoryStream.Create(Buffer); Decrypt := CryptoStream.Create(ST, Decryptor, CryptoStreamMode.Read); SetLength(Result, ST.Length); Decrypt.Read(Result, 0, ST.Length); end; xaromz [edit=Matze]Beitrag etwas angepasst. Mfg, Matze[/edit] |
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:54 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz