How to cleanse (overwrite with random bytes) std::string internal buffer?

后端 未结 3 1814
后悔当初
后悔当初 2021-02-12 06:00

Consider a scenario, where std::string is used to store a secret. Once it is consumed and is no longer needed, it would be good to cleanse it, i.e overwrit

3条回答
  •  南旧
    南旧 (楼主)
    2021-02-12 06:30

    std::string is a poor choice to store secrets. Since strings are copyable and sometimes copies go unnoticed, your secret may "get legs". Furthermore, string expansion techniques may cause multiple copies of fragments (or all of) your secrets.

    Experience dictates a movable, non-copyable, wiped clean on destroy, unintelligent (no tricky copies under-the-hood) class.

提交回复
热议问题