Re: Mit PHP verschlüsseln
Hi,
schau mal beim Michael beim FileCrypter. Dort ist eine Datei Encrypt.pas. In der ist ein Beispiel, wie man das DEC richtig verwendet. |
Re: Mit PHP verschlüsseln
Also bei mir funzt das nicht :wall:
Wende ich das richtig an? Delphi:
Delphi-Quellcode:
PHP:
var d : TCipher_Blowfish ;
begin d := TCipher_Blowfish.create; d.Mode := cmCBCx; d.Init('Passwort','12345678'); ShowMessage(Format('%10s: %s'+slinebreak+'%10s: %s',[ 'Delphi', d.EncodeBinary('Teststring',TFormat_HEX), 'PHP', IdHTTP1.Get('http://localhost/crypt/mawe.php')])); d.Free;
Code:
Die Ausgabe:
<?php
$key = "Passwort"; $input = "Teststring"; $encrypted = mcrypt_cbc(MCRYPT_BLOWFISH,$key ,$input,MCRYPT_ENCRYPT,'12345678'); echo bin2hex($encrypted); ?> --------------------------- Testprog --------------------------- Delphi: E51A3C77A4D01A2BA9D3 PHP: e51a3c77a4d01a2b4540b5e1767b982b --------------------------- OK --------------------------- Eins iss megakurz das andere länger.. kp.. :( |
Re: Mit PHP verschlüsseln
Zitat:
Auf PHP-Seite mußt Du jetzt "nur" noch zwei Sachen rauskriegen: 1. Welcher IV benutzt wird (random etc), und wie Du auf Delphiseite daran kommst. 2. Welches Padding benutzt wird, um auf volle Blocklänge aufzufüllen. Auf Delphiseite dann manuell einbauen. Willkommen im Cryptodschungel! Gruß Gammatester |
Re: Mit PHP verschlüsseln
Zitat:
Zu 1: Ich meine selbstverständlich den normalen Produktions-IV, bei Deinem Beispiel ist er ja '12345678'. Zu 2: Wenn man Deine Angaben durch Crypto++ jagt, kann ich den Ciphertext reproduzieren, wenn PKCS#7-Padding benutzt wird. Gruß Gammatester |
Re: Mit PHP verschlüsseln
Ich komm da nicht weiter :wall:
Habt ihr mir ein kleines funktionierendes Codebeispiel? Also PHP-Skript + Delphicode? (Ja ich weis normalerweise wird sowas hier nicht gemacht aber ich komm schlichtweg nicht weiter :( ) BTW: Das einzige was bisher funktioniert hat war ne einfach XOR Verschlüsselnung(kann man das Verschlüsselung nennen? :gruebel: ) und Base64. Beides aber ja nicht gerade sicher :pale: |
Re: Mit PHP verschlüsseln
:firejump::firejump::firejump::firejump: ES GEEEEHT!!! :firejump::firejump::firejump::firejump:
Delphi-Quellcode:
Und das PHP Pendant(Schreibt man das so? :gruebel: ) zur Encrypt Methode dazu:
const
KeySize = 32; // 32 bytes = 256 bits BlockSize = 8; // 16 bytes = 128 bits // Pad a string with zeros so that it is a multiple of size function PadWithZeros(const str : string; size : integer) : string; var origsize, i : integer; begin Result := str; origsize := Length(Result); if ((origsize mod size) <> 0) or (origsize = 0) then begin SetLength(Result,((origsize div size)+1)*size); for i := origsize+1 to Length(Result) do Result[i] := #0; end; end; procedure Encrypt; var Cipher : TDCP_blowfish; Data, Key, IV : string; tkey, tdata, tiv : string; begin tkey := '12345678901234567890123456789012'; tdata := 'Teststring'; tiv := '12345678'; // Pad Key, IV and Data with zeros as appropriate Key := PadWithZeros(tkey,KeySize); IV := PadWithZeros(tiv,BlockSize); Data := PadWithZeros(tdata,BlockSize); // Create the cipher and initialise according to the key length Cipher := TDCP_blowfish.Create(Self); if Length(tkey) <= 16 then Cipher.Init(Key[1],128,@IV[1]) else if Length(tkey) <= 24 then Cipher.Init(Key[1],192,@IV[1]) else Cipher.Init(Key[1],256,@IV[1]); // Encrypt the data Cipher.EncryptCBC(Data[1],Data[1],Length(Data)); // Free the cipher and clear sensitive information Cipher.Free; FillChar(Key[1],Length(Key),0); // Display the Base64 encoded result ShowMessage(Base64EncodeStr( Data)); end; procedure decrypt; var Cipher : TDCP_blowfish; Data, Key, IV : string; tkey, tdata, tiv : string; get : string; begin tkey := '12345678901234567890123456789012'; tdata := 'asdf'; tiv := '12345678'; get := IdHTTP1.Get('http://localhost/crypt/mawe.php'); // Pad Key and IV with zeros as appropriate Key := PadWithZeros(tkey,Keysize); IV := PadWithZeros(tiv,blocksize); // Decode the Base64 encoded string Data := Base64DecodeStr(get); // Create the cipher and initialise according to the key length Cipher := TDCP_blowfish.Create(Self); if Length(tkey) <= 16 then Cipher.Init(Key[1],128,@IV[1]) else if Length(tkey) <= 24 then Cipher.Init(Key[1],192,@IV[1]) else Cipher.Init(Key[1],256,@IV[1]); // Decrypt the data Cipher.DecryptCBC(Data[1],Data[1],Length(Data)); // Free the cipher and clear sensitive information Cipher.Free; FillChar(Key[1],Length(Key),0); // Display the result ShowMessage( Data+sLineBreak+get); end;
Code:
<?php
$key = "12345678901234567890123456789012"; $input = "Teststring"; $encrypted = mcrypt_cbc(MCRYPT_BLOWFISH,$key ,$input,MCRYPT_ENCRYPT,"12345678"); echo base64_encode($encrypted); ?> |
Re: Mit PHP verschlüsseln
Hallo Angel4585,
Inzwischen hast Du ja selbst eine Lösung gefunden. Ich wollte gerade nach einiger Zeit das (neben der Arbeit erstellte) Fragment unten abschicken. Bleibt jetzt eigentlich nur noch der Hinweis/Frage zum IV. Eigentlich sollte er ja nicht konstant sein, und müßte dann zwischen Delphi und PHP kommuniziert werden. Da er nicht geheim sein muss, kann man in zB als die ersten Zeichen versenden. Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:15 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