Sysprep 后无法解密安全字符串
Secure String can't be decrypted after Sysprep
我有两个正在为 Windows 7 图像构建的 PowerShell 脚本。在图像之前,我运行 PRE-IMAGE.ps1
,其中有这样一行:
$JoinDomainPassword = Read-Host -Prompt "Please enter the password for $joinDomainUser" -AsSecureString
$strPass = $joinDomainPassword | ConvertFrom-SecureString
然后我将 $strPass
安全字符串保存到注册表,然后运行 sysprep。
使用 sysprep 重新启动后,POST-IMAGE.ps1
然后从注册表中提取 $strPass
,并且有这样一行:
$strPass = $strPass | ConvertTo-SecureString
$credentials = New-Object System.Management.Automation.PSCredential ($JoinDomainUser, $strPass)
但是,POST-IMAGE.ps1
中的这些行会出现 "Key not valid" 错误,当您以不同的 Windows 用户运行 convertto-securestring
和 convertfrom-securestring
时,您会看到该错误。 (similiar to this question) - 但这里的问题是我 -AM- 使用同一个用户与安全字符串相互转换。我猜这与 sysprep 有关 - 但我无法理解它。
如果之前有人问过这个问题,我深表歉意,我发现有几个问题涉及部分内容,但没有描述我的确切问题。
如果您没有为 ConvertFrom-SecureString 命令指定密钥,它将使用 DPAPI 来加密字符串。 Sysprep 显然重新初始化了 DPAPI 使用的密钥。来自 http://www.mombu.com/microsoft/security-crypto/t-local-machine-masterkey-in-dpapi-1053937-print.html
DPAPI will generate the local system master key during the specialization phase of sysprep.
我有两个正在为 Windows 7 图像构建的 PowerShell 脚本。在图像之前,我运行 PRE-IMAGE.ps1
,其中有这样一行:
$JoinDomainPassword = Read-Host -Prompt "Please enter the password for $joinDomainUser" -AsSecureString
$strPass = $joinDomainPassword | ConvertFrom-SecureString
然后我将 $strPass
安全字符串保存到注册表,然后运行 sysprep。
使用 sysprep 重新启动后,POST-IMAGE.ps1
然后从注册表中提取 $strPass
,并且有这样一行:
$strPass = $strPass | ConvertTo-SecureString
$credentials = New-Object System.Management.Automation.PSCredential ($JoinDomainUser, $strPass)
但是,POST-IMAGE.ps1
中的这些行会出现 "Key not valid" 错误,当您以不同的 Windows 用户运行 convertto-securestring
和 convertfrom-securestring
时,您会看到该错误。 (similiar to this question) - 但这里的问题是我 -AM- 使用同一个用户与安全字符串相互转换。我猜这与 sysprep 有关 - 但我无法理解它。
如果之前有人问过这个问题,我深表歉意,我发现有几个问题涉及部分内容,但没有描述我的确切问题。
如果您没有为 ConvertFrom-SecureString 命令指定密钥,它将使用 DPAPI 来加密字符串。 Sysprep 显然重新初始化了 DPAPI 使用的密钥。来自 http://www.mombu.com/microsoft/security-crypto/t-local-machine-masterkey-in-dpapi-1053937-print.html
DPAPI will generate the local system master key during the specialization phase of sysprep.