Last active
January 16, 2016 02:06
-
-
Save jasongaylord/49a17a9bc49e38d7ca71 to your computer and use it in GitHub Desktop.
A Helper method to convert a string value to a SecureString value. This is most useful when needing to pass a sensitive value, such as a social security number or password, around as a string on the server side. The SecureString class has a Dispose method for GC.
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Security; | |
using System.Web; | |
namespace Gaylord.Helpers | |
{ | |
public static class SecureStringHelper | |
{ | |
public static SecureString ToSecureString(this string value) | |
{ | |
var rtn = new SecureString(); | |
if (value.Length > 0) | |
foreach (var c in value.ToCharArray()) | |
rtn.AppendChar(c); | |
return rtn; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment