/// <summary> /// Demonstrate how to convert SecureString into String /// </summary> static String SecureStringToString(SecureString value) { IntPtr bstr = Marshal.SecureStringToBSTR(value); try { return Marshal.PtrToStringBSTR(bstr); } finally { Marshal.FreeBSTR(bstr); } } /// <summary> /// Demonstrate how to convert String into SecureString /// </summary> static SecureString StringToSecureString(String value) { SecureString password = new SecureString(); char[] pass = value.ToCharArray(); for (int i = 0; i < pass.Length; i++) { password.AppendChar(pass[i]); } return password; }