![]() |
umwandlung von Delphi 7 in 2010 macht probs
Ich verwende folgenden Ver-Entschlüsselungscode um strings in (IRC-taugliches)-Blowfish zu verschlüsseln.
(hatte das mal irgendwo im netz gefunden)
Delphi-Quellcode:
Unter Delphi 7 gibs keine Probs aba unter 2010 funktioniert das en- und de-crypten nur zu 50%, ich hab schon die strings durch ansistrings und pchar duch pansichar ersetzt.
program Project1;
{$APPTYPE CONSOLE} uses SysUtils, madcrypt; const B64: ansistring = './0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; function PCindex(w: ansistring): Cardinal; begin Result:= Pos(w, B64); if Result > 0 then dec(Result); end; function PCsubstr(w: ansistring; i: Integer): ansichar; var s: ansistring; begin Result := #0; s:= Copy(w, i+1, 1); if (length(s) > 0) then Result:= s[1]; end; function bytetoB64(ec: ansistring): ansistring; var dc: ansistring; left, right: Cardinal; i, k : Integer; begin dc := ''; k := -1; while(k < (length(ec)-1)) do begin inc(k); left := (ord(PCsubstr(ec,k)) shl 24); inc(k); inc(left,(ord(PCsubstr(ec,k)) shl 16)); inc(k); inc(left, (ord(PCsubstr(ec,k)) shl 8)); inc(k); inc(left, ord(PCsubstr(ec,k))); inc(k); right := (ord(PCsubstr(ec,k)) shl 24); inc(k); inc(right,(ord(PCsubstr(ec,k)) shl 16)); inc(k); inc(right,(ord(PCsubstr(ec,k)) shl 8)); inc(k); inc(right, ord(PCsubstr(ec,k))); for i := 0 to 5 do begin dc := dc + PCsubstr(B64, right and $3F); right := right shr 6; end; for i := 0 to 5 do begin dc := dc + PCsubstr(B64, left and $3F); left := left shr 6; end; end; Result:= dc; end; function B64tobyte(ec: ansistring): ansistring; var dc: ansistring; k: Integer; i, right, left: Cardinal; begin dc:= ''; k := -1; while(k < (length(ec)-1)) do begin right := 0; left := 0; for i := 0 to 5 do begin inc(k); right := right or (PCindex(PCsubstr(ec, k)) shl (i * 6)); end; for i := 0 to 5 do begin inc(k); left := left or (PCindex(PCsubstr(ec, k)) shl (i * 6)); end; for i := 0 to 3 do begin dc := dc + chr((left and ($FF shl ((3 - i) * 8))) shr ((3 - i) * 8)); end; for i := 0 to 3 do begin dc := dc + chr((right and ($FF shl ((3 - i) * 8))) shr ((3 - i) * 8)); end; end; Result:= dc; end; function set_key(key: ansistring): ansistring; var i, keyLen: Integer; newkey: ansistring; begin Result := key; if(length(key) < 8) then begin keyLen := length(key); i := 8 div keyLen; if (8 mod keyLen > 0) then inc(i); newkey := ''; while (i > 0) do begin newkey := newkey + key; dec(i); end; Result := newkey; end; end; function EncryptIrcBlowfish(dText, key: ansistring): ansistring; stdcall; var temp, eText: ansistring; i: Integer; mykey: ansistring; begin eText := ''; if(dText<>'') then begin temp := ''; if (length(dText) mod 8 > 0) then for i:= 1 to 8 - (length(dText) mod 8) do dText:= dText+ #0; temp := ''; mykey:= set_key(key); for i:= 1 to length(dText) div 8 do begin temp:= Copy(dText, 1+(i-1)*8,8); SetLength(temp, 8); madcrypt.Encrypt(PansiChar(temp), 8, mykey); eText := eText + bytetoB64(temp); end; end; Result:= eText; end; function DecryptIrcBlowfish(eText, key: ansistring): ansistring; stdcall; var temp, dText: ansistring; i : Integer; mykey: ansistring; begin mykey:= set_key(key); for i:= 1 to length(eText) div 12 do begin temp := B64tobyte(Copy(eText,1+(i-1)*12,12)); SetLength(temp, 8); madcrypt.Decrypt(PansiChar(temp), 8, mykey); dText := dtext + temp; end; Result:= dText; end; var str, key, strEncrypted, strDecrypted: ansistring; begin try str := 't2e3s4t5t6e7st'; key := '123'; writeln('----'); strEncrypted := EncryptIrcBlowfish( str, key ); writeln('Encrypted: '+strEncrypted); strDecrypted := DecryptIrcBlowfish( strEncrypted, key ); writeln('DEcrypted: ' +strDecrypted); except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; readln; end. Wo könnte da noch der Fehler drin liegen?? :( |
AW: umwandlung von Delphi 7 in 2010 macht probs
Kommt dein verwendetes MadCrypt mit D2010 zurecht?
|
AW: umwandlung von Delphi 7 in 2010 macht probs
jup ist up to date für 2010
|
AW: umwandlung von Delphi 7 in 2010 macht probs
Ist MadCrypt komplett auf Unicode umgestellt
oder wurde es nur so umgestellt, daß es wenigstens lauffähig ist (also nur auf Ansi festgelegt)? Bei Ersterem sollte/könnte dein Code mit String/PChar (Unicode) funktionieren. Gibt es irgendwelche Compilermeldungen? |
AW: umwandlung von Delphi 7 in 2010 macht probs
Es soll alles auf ansistring angepasst/umgestellt worden sein.
Compiler Melungen gibs leider keine, nur halt die falschen Resultate die das crypten ausspuckt. Hab schon versucht, den unter Delphi 7 funzenden Code als DLL zu coden und denn halt mit 2010 die Dll einfach ansprechen. Aber da kommt auch nur wirrwarr heraus :( Wenn ich die Dll mit Delphi 7 hingegen anspreche funzt es aber.... |
AW: umwandlung von Delphi 7 in 2010 macht probs
Was übergibst du über das Interface zwischen der Dll und dem D2010 Programm?
|
AW: umwandlung von Delphi 7 in 2010 macht probs
D2010:
Delphi-Quellcode:
D7 DLL:
function EncryptIrcBlowfish(dText, key: ansistring): pansistring; stdcall; external 'project1.dll' name 'EncryptIrcBlowfish';
function DecryptIrcBlowfish(eText, key: ansistring): ansistring; stdcall; external 'project1.dll' name 'DecryptIrcBlowfish'; var str, key, strDecrypted, strEncrypted: ansistring; pstrEncrypted: pansistring; begin try str := 't2e3s4t5t6e7st'; key := '123'; writeln('----'); pstrEncrypted := EncryptIrcBlowfish( str, key ); strEncrypted := AnsiString(pstrEncrypted); writeln('Encrypted: '+strEncrypted); strDecrypted := DecryptIrcBlowfish( strEncrypted, key ); writeln('DEcrypted: ' +strDecrypted);
Delphi-Quellcode:
function EncryptIrcBlowfish(dText, key: ansistring): pansistring; stdcall;
var temp, eText: ansistring; i: Integer; mykey: ansistring; begin eText := ''; if(dText<>'') then begin temp := ''; if (length(dText) mod 8 > 0) then for i:= 1 to 8 - (length(dText) mod 8) do dText:= dText+ #0; temp := ''; mykey:= set_key(key); for i:= 1 to length(dText) div 8 do begin temp:= Copy(dText, 1+(i-1)*8,8); SetLength(temp, 8); madcrypt.Encrypt(PChar(temp), 8, mykey); eText := eText + bytetoB64(temp); end; end; Result:= pansistring(eText); end; function DecryptIrcBlowfish(eText, key: ansistring): ansistring; stdcall; var temp, dText: ansistring; i : Integer; mykey: ansistring; begin mykey:= set_key(key); for i:= 1 to length(eText) div 12 do begin temp := B64tobyte(Copy(eText,1+(i-1)*12,12)); SetLength(temp, 8); madcrypt.Decrypt(PChar(temp), 8, mykey); dText := dtext + temp; end; Result:= dText; end; exports EncryptIrcBlowfish, DecryptIrcBlowfish; |
AW: umwandlung von Delphi 7 in 2010 macht probs
AnsiStrings vor D2009 sind nicht mit denen ab Delphi2009 kompatibel.
und da hilft auch der nötige SharedMemoryManager nichts (welcher für derartige Speicherübergaben nötig ist), da die interne Struktur der Strings um 2 sinnlose und mehr Probleme bereitende, als lösende Felder erweitert wurde. Ergo: Du kannst nur eine Schnittstelle mit PAnsiChar verwenden. |
AW: umwandlung von Delphi 7 in 2010 macht probs
thx, endlich hinbekommen mit PAnsiChar die D7 DLL anzusprechen mit korrekten Ausgaben :)
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:23 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