Using SecureString

前端 未结 8 858
醉梦人生
醉梦人生 2020-12-24 00:56

Can this be simplified to a one liner? Feel free to completely rewrite it as long as secureString gets initialized properly.

SecureString secureString = new          


        
8条回答
  •  借酒劲吻你
    2020-12-24 01:43

    Just use NetworkCredential. It has the conversion logic built-in.

    SecureString ss = new NetworkCredential("", "fizzbuzz").SecurePassword;
    

    As others have noted, all of these techniques strip the security benefits of SecureString, but in certain situations (such as unit tests) this may be acceptable.

    Update:

    As noted in the comments, NetworkCredential can also be used to convert a SecureString back to a string.

    string s = new NetworkCredential("", ss).Password;
    

提交回复
热议问题