How do I securely erase std::wstring?

I am unsure if I should have posted this in the Windows Programming forum, so let me know.

I have sensitive data shared across multiple processes using #pragma comment(linker, "Shared:rws"). They are two C strings of 1K characters. I am encrypting these using CryptProtectMemory() and I decrypt it whenever I need using a class that synchronizes access across the processes using a mutex. The result is a std::wstring object containing the unencrypted data.

I think I should create a new class, namely securewstring, that securely erases the buffer using SecureZeroMemory() and that inherits from std::wstring.

So the question would be: Is there an already-made secure string in STL? If not, can you point me in the right direction about creating a new one? What's the name of the pointer containing the buffer and its size? What should I override? I would imagine I need a new destructor. What else? Operator=? Or can I just override a "clean up" method that is called by all those?
Is there an already-made secure string in STL?
No.

What's the name of the pointer containing the buffer and its size?
What do you mean?

What should I override?
If you're talking about deriving std::wstring, none of the STL containers, including std::basic_string, are designed to be derived.

If SecureZeroMemory() does what its name suggests, you could pass it &str[0] and the size, and it should have the desired effect.
Topic archived. No new replies allowed.