Differences
This shows you the differences between the selected revisions of the page.
| 2021-06-14 | 2023-12-27 | ||
| removing comment (martin) | making the code compatible with .net [core] and powershell [core] (martin) | ||
| Line 2: | Line 2: | ||
| The following PowerShell script can be used to decrypt files [[file_encryption|encrypted by WinSCP]], when you do not have WinSCP available. | The following PowerShell script can be used to decrypt files [[file_encryption|encrypted by WinSCP]], when you do not have WinSCP available. | ||
| + | |||
| + | //The script works both in legacy Windows PowerShell and modern PowerShell [Core], though it runs much slower in the latter.// | ||
| //For C# version of the ''AesCtrTransform'' function, see [[https://stackoverflow.com/q/6374437/850848#51188472|Can I use AES in CTR mode in .NET?]]// | //For C# version of the ''AesCtrTransform'' function, see [[https://stackoverflow.com/q/6374437/850848#51188472|Can I use AES in CTR mode in .NET?]]// | ||
| Line 24: | Line 26: | ||
| $counter = $salt.Clone() | $counter = $salt.Clone() | ||
| - | $xorMask = New-Object System.Collections.Queue<byte> | + | $xorMask = New-Object System.Collections.Generic.Queue[byte] |
| $zeroIv = New-Object byte[] $blockSize | $zeroIv = New-Object byte[] $blockSize | ||
| Line 66: | Line 68: | ||
| $aes = New-Object System.Security.Cryptography.AesManaged | $aes = New-Object System.Security.Cryptography.AesManaged | ||
| - | $key = [System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary]::Parse($key).Value | + | try |
| + | { | ||
| + | # .NET >= 5 | ||
| + | $key = [System.Convert]::FromHexString($key) | ||
| + | } | ||
| + | catch [System.Management.Automation.RuntimeException] | ||
| + | { | ||
| + | # .NET Framework | ||
| + | ········$key = [System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary]::Parse($key).Value | ||
| + | } | ||
| $keySize = $aes.KeySize / 8 | $keySize = $aes.KeySize / 8 | ||
| if ($key.Length -ne $keySize) | if ($key.Length -ne $keySize) | ||