![]() |
Passwort in Ini-datei speichern
Liste der Anhänge anzeigen (Anzahl: 1)
Folgendes Problem beim Verschlüsseln:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var Ini: TIniFile; s: String[255]; c: array[0..255] of Byte absolute s; i: Integer; begin Ini:=TIniFile.Create(ExtractFilePath(ParamStr( 0 )) + '\settings.ini'); try s := Edit4.Text; for i := 1 to Length(s) do s[i] := Char(23 xor Ord(c[i])); // das Problem ist Char Ini.WriteString('mySQl', 'Server', Edit1.Text); Ini.WriteString('mySQl', 'Port', Edit2.Text); Ini.WriteString('mySQl', 'User', Edit3.Text); Ini.WriteString('mySQl', 'Passwort', s); Ini.WriteString('mySQl', 'Datenbank', Edit5.Text); finally Ini.Free; end; end; |
AW: Passwort in Ini-datei speichern
Unverschlüsselt speichern ist immer eine schlechte Idee!
XOR ist keine Verschlüsselung! |
AW: Passwort in Ini-datei speichern
mach mal aus dem s : string[255]; ein string.
|
AW: Passwort in Ini-datei speichern
Zitat:
Man beachte das absolute. Wenn, dann muß man noch mehr umbauen. Problem ist hier, dass seit Delphi 2009 der String Unicode ist, aber der Typ String[x] blieb weiterhin ANSI. Auch bei der Ver-/Entschlüsselung von Zeichen über #127 (kein ASCII) kommt eventuell was Falsches raus, wenn man es einfach so auf Unicode umstellt. (2 Byte statt 1 Byte)
Delphi-Quellcode:
s := AnsiString(Edit4.Text);
for i := 1 to Length(s) do s[i] := AnsiChar(23 xor Ord(c[i]) |
AW: Passwort in Ini-datei speichern
Zitat:
|
AW: Passwort in Ini-datei speichern
Also XOR ist nicht gerade schön und wirklich nicht zu empfehlen.
Wenn es minimale Sicherheit sein soll, dann würde ich das eventuell so machen:
Delphi-Quellcode:
const
Code64 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/'; function Encode64(S: string): string; function Decode64(S: string): string; {-------------------------------------------------------------------------------} function Encode64(S: string): string; var I: Integer; a: Integer; x: Integer; b: Integer; begin Result := ''; a := 0; b := 0; for I := 1 to Length(S) do begin x := Ord(S[I]); b := b * 256 + x; a := a + 8; while a >= 6 do begin a := a - 6; x := b div (1 shl a); b := b mod (1 shl a); Result := Result + Code64[x + 1]; end; end; if a > 0 then begin x := b shl (6 - a); Result := Result + Code64[x + 1]; end; end; function Decode64(S: string): string; var I: Integer; a: Integer; x: Integer; b: Integer; begin Result := ''; a := 0; b := 0; for I := 1 to Length(S) do begin x := Pos(S[I], Code64) - 1; if x >= 0 then begin b := b * 64 + x; a := a + 6; if a >= 8 then begin a := a - 8; x := b shr a; b := b mod (1 shl a); x := x mod 256; Result := Result + chr(x); end; end else Exit; end; end; |
AW: Passwort in Ini-datei speichern
Ich möchte hier auf Synopse verweisen.
Code:
Und dann nutzen mit
unit uSimpleEncryption;
interface uses SynCommons, SynCrypto; function encrypt(aString:String):String; function decrypt(aString:String):String; implementation const my_key = 'derVerschLuessElLungsKeyimmerWiederNett'; function encrypt(aString:String):String; var key : TSHA256Digest; aes : TAESCFB; s:RawByteString; begin SynCommons.HexToBin(Pointer(SHA256(my_key)), @key, 32); aes := TAESCFB.Create(key, 256); try s := StringToUTF8(aString); s := BinToBase64(aes.EncryptPKCS7(s, True)); Result := UTF8ToString(s); finally aes.Free; end; end; function decrypt(aString:String):String; var key : TSHA256Digest; aes : TAESCFB; s:RawByteString; begin SynCommons.HexToBin(Pointer(SHA256(my_key)), @key, 32); aes := TAESCFB.Create(key, 256); try s := StringToUTF8(aString); s := aes.DecryptPKCS7(Base64ToBin(s), True); Result := UTF8ToString(s); finally aes.Free; end; end; end.
Code:
bzw.
Encrypt(sApiPassword);
Code:
Decrypt(sEncryptedString);
|
AW: Passwort in Ini-datei speichern
Zitat:
![]() Grüße, Andreas |
AW: Passwort in Ini-datei speichern
|
AW: Passwort in Ini-datei speichern
Danke für die Richtigstellung und den korrekten Link! Ich habe nur die Version mit a gekannt. :oops:
Grüße, Andreas |
AW: Passwort in Ini-datei speichern
Zitat:
Die beste Lösung habe ich vor rund 20 Jahren in den Newsgroups gelesen (müsste damals von MM gewesen sein): Pack die Credentials im Klartext in die readme. Die liest nämlich nie jemand. |
AW: Passwort in Ini-datei speichern
Ich darf natürlich auch Delphi Encryption Compendium (DEC) empfehlen.
Da aber die Vollversion von Github: ![]() Dort werden auch diverse Beispielprogramme mitgeliefert. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:05 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 by Thomas Breitkreuz