Created
January 30, 2014 15:37
-
-
Save tgnm/8711220 to your computer and use it in GitHub Desktop.
Convert SecureString to String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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