Einzelnen Beitrag anzeigen

amigage

Registriert seit: 11. Nov 2005
Ort: Leipzig
270 Beiträge
 
Delphi 11 Alexandria
 
#11

AW: DCPCrypt in RAD Studio 10.3/10.4

  Alt 23. Nov 2020, 12:36
Leider bräuchte ich hier ein wenig Hilfe.
Das Enkodieren und Umwandeln in Base64 fuktioniert soweit.

Delphi-Quellcode:
procedure TForm1.btnEncodeClick(Sender: TObject);
var
  Cipher_Mars : TCipher_mars;
  Ciphertext: TBytes;
  PlainText : Binary;

  strEncoded : TFormat_MIME64;
begin
   Plaintext := Edit1.Text;
   Cipher_Mars := TCipher_Mars.Create;
   strEncoded := TFormat_MIME64.Create;
   try
     Cipher_Mars.Mode := cmCBCx;
     Cipher_Mars.Init(password);
     SetLength(Ciphertext, Length(Plaintext));
     Cipher_Mars.Encode(Plaintext[1], Ciphertext[0], Length(Plaintext));

     Edit2.Text := strEncoded.Encode(CipherText, Length(Ciphertext));
   finally
     strEncoded.Free;
     Cipher_Mars.Free;
   end;
end;
Jedoch bekomme ich es nicht wieder dekodiert. Bei Cipher_Mars.Decode wird eine Zugriffsverletzung ausgegeben.

Delphi-Quellcode:
procedure TForm1.btnDecodeClick(Sender: TObject);
var
  Cipher_Mars : TCipher_mars;
  Ciphertext: TBytes;
  Mime64Text : Binary;

  strEncoded : TFormat_MIME64;
  strOriginalText : String;
  strDecoded : RawByteString;
begin
   Mime64Text := Edit2.Text;
   Cipher_Mars := TCipher_Mars.Create;
   strEncoded := TFormat_MIME64.Create;
   try
     strDecoded := strEncoded.Decode(Mime64Text);
     Ciphertext := BytesOf(strDecoded);

     Cipher_Mars.Mode := cmCBCx;
     Cipher_Mars.Init(password);
     Cipher_Mars.Decode(Ciphertext[0], strOriginalText[1], Length(Ciphertext));

     Edit3.Text := strOriginalText;
   finally
     strEncoded.Free;
     Cipher_Mars.Free;
   end;
end;
Übersehe ich hier irgendetwas?
  Mit Zitat antworten Zitat