Powershell 将密码从文件中的安全文本转换为纯文本

Powershell 将密码从文件中的安全文本转换为纯文本,powershell,Powershell,我在powershell中有一个名为SecureText.ps1的脚本。它所做的是提示用户输入密码,然后将其转换为胡言乱语,这样密码就安全了。 SecuredText.ps1 param([string] $FilePath = (([Environment]::GetFolderPath("myDocuments")+"\SecuredText.txt"))) #SecureText.ps1 #Program the secures text that is only accessable t

我在powershell中有一个名为SecureText.ps1的脚本。它所做的是提示用户输入密码,然后将其转换为胡言乱语,这样密码就安全了。 SecuredText.ps1

param([string] $FilePath = (([Environment]::GetFolderPath("myDocuments")+"\SecuredText.txt")))
#SecureText.ps1
#Program the secures text that is only accessable to the user. Defaults to the person "MyDoucments"
$SecurePassword = Read-Host -Prompt "Enter password" -AsSecureString | ConvertTo-SecureString -AsPlainText -Force
$SecurePassword | ConvertFrom-SecureString  | Out-File -FilePath $FilePath
$SecurePassword = $null
然后,我尝试使用这些命令将其转换为纯文本

$Password = Get-Content C:\Users\fpettigrosso\Documents\SecuredText.txt | ConvertTo-SecureString -AsPlainText -Force
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password)
$PlainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
Write-Host $PlainPassword

我希望找回密码,但我只是找回了胡言乱语。如何获得密码而不是胡言乱语?

您生成和解密的密码不正确

## Generation
Read-Host -Prompt 'Enter password' -AsSecureString |
    ConvertFrom-SecureString |
    Out-File -FilePath $Path


使用securepassword创建一个
[pscredential]
对象,然后调用
.GetNetworkCredential().Password
。用户名不重要注意:SecureString只能在创建它的同一个用户帐户和硬件上解密。@TheIncorrigible1尝试了这种方法,但仍然得到了jiberish.OOPS。。我尝试时忘记调用get network credential。非常感谢。
## Decryption
(New-Object -TypeName PSCredential -ArgumentList @(
    'user',
    ((Get-Content -Path $Path) | ConvertTo-SecureString)
)).GetNetworkCredential().Password