PowerShell 中的示例如下所示:
$key = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
$secureText = ConvertTo-SecureString -String 'user_spassword' -AsPlainText -Force
$result = ConvertFrom-SecureString -SecureString $secureText -Key $key
$result
如何在不使用
System.Management.Automation.PowerShell
类的情况下获得相同的结果?
可以代替使用
System.Security.Cryptography.Aes
或 Microsoft.PowerShell.Commands.ConvertFromSecureStringCommand
类吗?
没有一个使用密钥和加密类在文件中创建编码字符串的示例。
有点粗暴但简单的方法是(ab)使用
System.Net.NetworkCredential
:
SecureString secure = ...;
var cred = new NetworkCredential("", secure);
Console.Write($"Insecure secure {cred.Password}";
string insecure = "something";
var cred = new NetworkCredential("", insecure);
Console.Write($"Secure insecure {cred.SecurePassword.Length}";