powershell - 有没有办法对任何用户使用 ConvertFrom-SecureString 和 ConvertTo-SecureString?

标签 powershell windows-10

我使用以下内容来创建密码文件:

$path = "C:\Users\USER\Desktop"
$passwd = Read-Host "enter desired password" -AsSecureString
$encpwd = ConvertFrom-SecureString $passwd
$encpwd > $path\filename.bin

然后使用以下命令调用文件:

# define path to store password and input password 
$path = "C:\Users\USER\Desktop"
# get the encrypted password from the path
$encpwd = Get-Content $path\filename.bin
# convert file to secure string 
$passwd = ConvertTo-SecureString $encpwd
# define needed credential 
$cred = new-object System.Management.Automation.PSCredential 'WIN-SERVER\AdminForQB',$passwd
# go to DVD drive launch setup.exe as user with privileges to launch the program with no user input required
Set-Location "C:\Program Files (x86)\Intuit\QuickBooks 2017\"
Start-Process PowerShell -windowstyle hidden -Cred $cred -ArgumentList .\QBW32PremierAccountant.exe

我的目标是能够使用管理员权限运行 QB2017,而无需授予用户管理员权限。我遇到的问题是,我必须为每个用户生成密码文件,否则如果用户尝试使用其他用户生成的密码文件,则会出现以下错误:

Key not valid for use in specified state.

有没有办法在不为每个用户生成 key 的情况下使用此方法?

最佳答案

当您在没有 KeySecureKey 的情况下使用 ConvertTo-SecureStringConvertFrom-SecureString 时,Powershell 将使用用于加密/解密字符串的 Windows 数据保护 API (DPAPI)。这意味着它仅适用于同一台计算机上的同一用户。

当您使用 Key/SecureKey 时,将使用高级加密标准 (AES) 加密算法。只要您知道所使用的 AES key ,您就可以将任何计算机上存储的凭据与任何用户一起使用。

More info on this topic (with example code)

注意:这只是通过模糊实现安全性,这不是一个好的做法。如果您将 key 与加密密码存储在同一台计算机上,它并不比纯文本密码安全多少!

关于powershell - 有没有办法对任何用户使用 ConvertFrom-SecureString 和 ConvertTo-SecureString?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46547174/

相关文章:

powershell - 如何通过 PowerShell 设置 SharePoint 托管应用程序的权限?

sqlite - UWP 中的密码保护 Sqlite

audio - 使用浏览器时无声音

powershell - 向 csv 文件添加条目会引发错误 :does not contain a method named 'op_Addition'

powershell - 正确编辑变量值

windows - Ansible 剧本,在提升模式下使用特定(域)用户运行 powershell 脚本的正确语法是什么?

.net - 使用 Get-Member 进行反射

带 JNA+DLL 的 Java 程序在 C :\Program Files on Win10? 下需要 "Run as Administrator"

angularjs - Cordova url 和图像 src 在 Windows 中的 url 前面有 'unsafe'

Windows 10 崩溃,无法启动