Reputation: 11
I am getting the “input” from the server in “Base64-encoded” form as shown in picture.
original = base64_decode(input)
.to_be_hash =password (known value) + input
.binary_hash_str =sha256(to_be_hash)
.I need Base64 URL-safe encode the binary hash string above to make it suitable for HTTP requests.
final_hash = base64_url_safe_encode(binary_hash_str)
I am using powershell for this. Can someone guide me how to progress please.
Upvotes: 1
Views: 2796
Reputation: 1216
The correct way of doing this is shown here: https://www.powershellgallery.com/packages/Posh-ACME/2.0.1/Content/Private%5CConvertTo-Base64Url.ps1
Base64Url-encode is not the same as Base64-encode + Url-encode.
Upvotes: 1
Reputation: 5114
If I understand correctly you would like to send a base64 string as a argument in a url? You can escape the characters that are not acceptable in a url using [uri]::EscapeDataString()
$text = "some text!!"
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)
$base64 = [System.Convert]::ToBase64String($bytes)
$urlSafeString = [uri]::EscapeDataString($base64)
"Base64 : " + $base64
"urlSafeString : " + $urlSafeString
Base64 : cwBvAG0AZQAgAHQAZQB4AHQAIQAhAA==
urlSafeString : cwBvAG0AZQAgAHQAZQB4AHQAIQAhAA%3D%3D
Upvotes: 2