Am trying to obsfuscate the API key from zscaler
https://help.zscaler.com/zia/api-getting-started, but they have no documentation for powershell.
I did the conversion from javascript to powershell : Here the function for your information
Function Obfuscate {
PARAM (
[Parameter(Mandatory=$true,HelpMessage="apiKey")][String] $key,
[Parameter(Mandatory=$true,HelpMessage="Timestamp")]$timestamp
)
$apiKey=""
$high=$Timestamp.substring($timestamp.length -6)
$low=$high -shr 1
$low=$low.ToString()
While ($low.length -lt 6) {$low="0"+$low}
For ($i=0;$i -lt $high.length; $i++) {
$apiKey+=$key.substring($high.substring($i,1) -shr 0,1)
}
For ($i=0;$i -lt $low.length; $i++) {
$apiKey+=$key.substring(($low.substring($i,1) -shr 0)+2,1)
}
return $apiKey
}
It remains only one problem , that is very annoying :
Date.now() (for the timestamp variable) in javascript/java/python and son return a 13 digit number (1519984360183) (which is supposed to be time in second since 1970/01/01 00:00:00:00)
The similar function in powershell :
$timestamp=([Math]::Floor([decimal](Get-Date(Get-Date).ToUniversalTime()-uformat "%s"))).tostring()
or
$timestamp = (Get-Date -UFormat %s)
Return a 15 digits number
Running the script to send a post request with a 15 digits timestamp give an error as Zscaler server doesn’t recognize the obfuscated api key.
Any idea ?