how does one securely clear std::string?

前端 未结 6 857
后悔当初
后悔当初 2020-11-30 07:43

How does one store sensitive data (ex: passwords) in std::string?

I have an application which prompts the user for a password and passes it to a downstr

6条回答
  •  无人及你
    2020-11-30 08:20

    std::string mystring;
    ...
    std::fill(mystring.begin(), mystring.end(), 0);
    

    or even better write your own function:

    void clear(std::string &v)
    {
      std::fill(v.begin(), v.end(), 0);
    }
    

提交回复
热议问题