Decrypt an encrypted password
$KeyFile = "$ENV:UserProfile\.pass\aes.key"
$Key = Get-Content $KeyFile
$datafile = Join-Path -Path $PsScriptRoot -ChildPath 'encryptedthings.csv'
(import-csv $datafile) |
Foreach-Object {
if($_.AccountPassword)
{
$Securestring = ConvertTo-SecureString $_.AccountPassword -Key $key
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Securestring)
$DecryptedPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
}
else {
$DecryptedPassword = ''
}
Expected behavior
This code snippet works and has been working for some time on Windows PowerShell 5.x and PowerShell Core 6.x on OSX and Linux.
Actual behavior
ConvertTo-SecureString : Input string was not in a correct format.
At C:\Program Files\PowerShell\Modules\mymodule\0.0.0.2\Public\Get-stuff.ps1:53 char:37
+ ... $Securestring = ConvertTo-SecureString $_.AccountPassword -Key $key
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [ConvertTo-SecureString], FormatException
+ FullyQualifiedErrorId : System.FormatException,Microsoft.PowerShell.Commands.ConvertToSecureStringCommand
Environment data
Name Value
---- -----
PSVersion 7.0.0-preview.4
PSEdition Core
GitCommitId 7.0.0-preview.4
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Decrypt an encrypted password
Expected behavior
This code snippet works and has been working for some time on Windows PowerShell 5.x and PowerShell Core 6.x on OSX and Linux.
Actual behavior
Environment data