How to convert SecureString to System.String?

后端 未结 11 848
孤独总比滥情好
孤独总比滥情好 2020-11-27 10:22

All reservations about unsecuring your SecureString by creating a System.String out of it aside, how can it be done?

How can I convert an ordinary S

11条回答
  •  孤街浪徒
    2020-11-27 11:02

    If you use a StringBuilder instead of a string, you can overwrite the actual value in memory when you are done. That way the password won't hang around in memory until garbage collection picks it up.

    StringBuilder.Append(plainTextPassword);
    StringBuilder.Clear();
    // overwrite with reasonably random characters
    StringBuilder.Append(New Guid().ToString());
    

提交回复
热议问题