I am trying to figure out how to the code reported below works.
$number =+313331234568
$key = [System.Text.Encoding]::Unicode.GetBytes('9999b9bc-99a9-99e9-b999-999f9a999c9d')
$s = ConvertTo-SecureString -String $number -AsPlainText -Force | ConvertFrom-SecureString -Key $key[1..32]
return $s
Please, can you help me to understand how to code reported works?
It's not very clear how the value in the brackets after the key is used against the byte array obtained from Write-Host $key
, this is the output:
57 0 57 0 57 0 57 0 98 0 57 0 98 0 99 0 45 0 57 0 57 0 97 0 57 0 45 0 57 0 57 0 101 0 57 0 45 0 98 0 57 0 57 0 57 0 45 0 57 0 57 0 57 0 102 0 57 0 97 0 57 0 57 0 57 0 99 0 57 0 100 0
PS C:\Users\admin> Write-Host $key 57 0 57 0 57 0 57 0 98 0 57 0 98 0 99 0 45 0 57 0 57 0 97 0 57 0 45 0 57 0 57 0 101 0 57 0 45 0 98 0 57 0 57 0 57 0 45 0 57 0 57 0 57 0 102 0 57 0 97 0 57 0 57 0 57 0 99 0 57 0 100 0 PS C:\Users\admin> $keym = (57 ,57 ,57 ,57 ,98 ,57 ,98 ,99 ,45 ,57 ,57 ,97 ,57 ,45 ,57 ,57 ,101 ,57 ,45 ,98 ,57 ,57 ,57 ,45 ,57 ,57 ,57 ,102 ,57 ,97 ,57 ,57 ,57 ,99 ,57 ,100) PS C:\Users\admin> $s = ConvertTo-SecureString -String $number -AsPlainText -Force | ConvertFrom-SecureString -Key $keym ConvertFrom-SecureString : Valore key non valido. La lunghezza valida per key deve essere 128 bit, 192 bit o 256 bit. In riga:1 car:67 + ... ing $number -AsPlainText -Force | ConvertFrom-SecureString -Key $keym + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [ConvertFrom-SecureString], PSArgumentException + FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.ConvertFromSecureStringCommand
I would like to apply the same decrypt/encrypt but using OpenSSL on Unix instead.