How to convert SecureString to System.String?

后端 未结 11 840
孤独总比滥情好
孤独总比滥情好 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条回答
  •  萌比男神i
    2020-11-27 10:59

    // using so that Marshal doesn't have to be qualified
    using System.Runtime.InteropServices;    
    //using for SecureString
    using System.Security;
    public string DecodeSecureString (SecureString Convert) 
    {
        //convert to IntPtr using Marshal
        IntPtr cvttmpst = Marshal.SecureStringToBSTR(Convert);
        //convert to string using Marshal
        string cvtPlainPassword = Marshal.PtrToStringAuto(cvttmpst);
        //return the now plain string
        return cvtPlainPassword;
    }
    

提交回复
热议问题