Skip to content

Instantly share code, notes, and snippets.

@tgnm
Created January 30, 2014 15:37
Show Gist options
  • Save tgnm/8711220 to your computer and use it in GitHub Desktop.
Save tgnm/8711220 to your computer and use it in GitHub Desktop.
Convert SecureString to String
public static string ConvertToUnsecureString(this SecureString securePassword)
{
if (securePassword == null)
throw new ArgumentNullException("securePassword");
IntPtr unmanagedString = IntPtr.Zero;
try
{
unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(securePassword);
return Marshal.PtrToStringUni(unmanagedString);
}
finally
{
Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment