diff --git a/src/chocolatey/StringExtensions.cs b/src/chocolatey/StringExtensions.cs index 62ab04ff7e..55c1f90528 100644 --- a/src/chocolatey/StringExtensions.cs +++ b/src/chocolatey/StringExtensions.cs @@ -17,6 +17,7 @@ namespace chocolatey { using System; using System.Globalization; + using System.Security; using System.Text.RegularExpressions; using infrastructure.app; using infrastructure.logging; @@ -83,6 +84,26 @@ public static string to_string(this string input) return input; } + /// + /// Takes a string and returns a secure string + /// + /// The input. + /// + public static SecureString to_secure_string(this string input) + { + var secureString = new SecureString(); + + if (string.IsNullOrWhiteSpace(input)) return secureString; + + foreach (char character in input) + { + secureString.AppendChar(character); + } + + return secureString; + } + + private static readonly Regex _spacePattern = new Regex(@"\s", RegexOptions.Compiled); ///