How can I increase memory security in Delphi?

前端 未结 11 1674
醉酒成梦
醉酒成梦 2020-12-11 09:50

Is it possible to \"wipe\" strings in Delphi? Let me explain:

I am writing an application that will include a DLL to authorise users. It will read an encrypted file

11条回答
  •  孤城傲影
    2020-12-11 10:18

    How about something like this?

    procedure WipeString(const str: String);
    var
      i:Integer;
      iSize:Integer;
      pData:PChar;
    
    begin
        iSize := Length(str);
        pData := PChar(str);
    
        for i := 0 to 7 do
        begin
          ZeroMemory(pData, iSize);
          FillMemory(pData, iSize, $FF); // 1111 1111
          FillMemory(pData, iSize, $AA); // 1010 1010
          FillMemory(pData, iSize, $55); // 0101 0101
          ZeroMemory(pData, iSize);
        end;
    end;
    

提交回复
热议问题