Secure way to store password in Windows

前端 未结 3 404
孤街浪徒
孤街浪徒 2020-12-13 21:53

I\'m trying to protect a local database that contains sensitive info (similar to this question, only for delphi 2010)

I\'m using DI

3条回答
  •  被撕碎了的回忆
    2020-12-13 22:08

    Ok, here's an example using TurboPower Lockbox (version 2)

      uses LbCipher, LbString;
    
      TaAES = class
      private
        Key: TKey256;
        FPassword: string;
      public
        constructor Create;
    
        function Code(AString: String): String;
        function Decode(AString: String): String;
    
        property Password: string read FPassword write FPassword;
      end;
    
    function TaAES.Code(AString: String): String;
    begin
      try
        RESULT := RDLEncryptStringCBCEx(AString, Key, SizeOf(Key), False);
      except
        RESULT := '';
      end;
    end;
    
    constructor TaAES.Create;
    begin
      GenerateLMDKey(Key, SizeOf(Key), Password);
    end;
    
    function TaAES.Decode(AString: String): String;
    begin
      RESULT := RDLEncryptStringCBCEx(AString, Key, SizeOf(Key), True);
    end;
    

    You can save your password as variable in your application. Without save to file example but you can use TFileStream to save encrypted(code) password and then decode it to read it :-)

提交回复
热议问题