为什么安全字符串需要force和AsPlainText

时间:2017-07-27 15:26:25

标签: powershell

我目前正在通过在线教程学习PowerShell。

为什么示例在创建安全字符串时使用-Force-AsPlainText会有什么好处?

$password = 'P@ssw0rd' | ConvertTo-SecureString -AsPlainText -Force

2 个答案:

答案 0 :(得分:3)

使用这些参数没有任何好处,相反,它们需要表明您理解您的字符串不安全,尽管您现在已将其置于SecureString中。因为你已经将它作为纯文本传递,所以它已经以不安全的方式存在于记忆中。

-AsPlainText表示您希望将其作为纯文本参数传递。 -Force is documented as

  

确认您了解使用 AsPlainText 参数的含义并仍想使用它。

答案 1 :(得分:0)

IIRC,-Force会阻止来自-AsPlainText

的确认提示
$PW = ConvertTo-SecureString -String 'P@ssw0rd' -AsPlainText -Force