【发布时间】:2014-07-24 05:44:07
【问题描述】:
我们正在尝试将用户密码作为安全字符串存储在注册表中,但我们似乎无法找到将其转换回纯文本的方法。 SecureString 可以做到这一点吗?
这是我们尝试使用的简单测试脚本...
Write-Host "Test Start..."
$PlainPassword = "@SomethingStupid" | ConvertTo-SecureString -AsPlainText -Force
$BSTR = ` [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($PlainPassword)
$PlainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
Write-Host "Password is: " $PlainPassword
Read-Host
这是我们得到的错误...
The term ' [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR'
is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\test.ps1:4 char:71
+ $BSTR = ` [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR
<<<< ($PlainPassword)
+ CategoryInfo : ObjectNotFound: (
[System.Runtim...ureStringToBSTR:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Cannot find an overload for "PtrToStringAuto" and the argument count: "1".
At C:\test.ps1:5 char:75
+ $PlainPassword =
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto <<<< ($BSTR)
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
【问题讨论】:
-
尝试不要用反勾号包裹 $BTSR 行
-
给我一个语法错误... "Unexpected Token"
-
好的,首先尝试将明文放入自己的字符串变量中,就像我认为您正在查看的文章中一样 - social.technet.microsoft.com/wiki/contents/articles/…
-
嗯 - 您运行的是什么操作系统、.NET 和 Powershell 版本?
-
对不起,你是对的,后面的勾号是问题所在。当我最初删除它时,我从命令中删除了第一个字符,这就是意外的令牌错误。
标签: powershell encryption