ExtensionMethod.NET Home of 818 C#, Visual Basic, F# and Javascript extension methods

ToSecureString

Converts a string into a "SecureString"

Source

/// <summary>
/// Converts a string into a "SecureString"
/// </summary>
/// <param name="str">Input String</param>
/// <returns></returns>
public static System.Security.SecureString ToSecureString(this String str)
{
    System.Security.SecureString secureString = new System.Security.SecureString();
    foreach (Char c in str)
        secureString.AppendChar(c);

    return secureString;
}

Example

String password = "mypassword";
System.Security.SecureString secure = password.ToSecureString();

Author: Jonnidip

Submitted on: 28 mei 2009

Language: C#

Type: System.String

Views: 9945