I want to Base64 URL-safe encode my "binary hash string" value that comes as input from my previous code line to make it suitable for HTTP requests, ie final_hash = base64_url_safe_encode(binary_hash_str). Where i can use the final hashed password for authentication purpose in powershell. I was not able to find any code in powershell.
Converting a byte array to base64 in PowerShell can be done with [Convert]::ToBase64String()
:
$binString = [System.Text.Encoding]::UTF8.GetBytes("Secret string")
$base64String = [Convert]::ToBase64String($binString)
If you want to use the resulting base64 string as part of the request payload (eg. a header or part of the request body), you can go ahead and use it as is:
Invoke-WebRequest $uri -Header @{ Authorization = "Basic ${base64String}"}
If you need to pass it as a query parameter in the url itself, escape it with [uri]::EscapeDataString()
:
$URI = 'https://domain.tld/path?param={0}' -f [uri]::EscapeDataString($base64String)
Invoke-WebRequest $URI
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.