I have a strange issue that I am finding when decoding base64 strings in Powershell.
$url = "https://*******.search.windows.net/indexes/azureblob-index/docs?api-version=2019-05-06&search=*"
$headers = @{
"api-version" = "2019-05-06"
"Content-Type" = "application/json"
"api-key" = "**********"
}
$result = Invoke-webrequest -Uri $url -Headers $headers -Method Get | ConvertFrom-Json
$values = $result.value
foreach ($value in $values)
{
$path = $value.metadata_storage_path
$bloburl = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($path))
$bloburl
}
The **** are hiding sensitive information, obviously.
So I am trying to return an Azure blob URL which is encoded. It managed to decode, however, it returns and error and seems to add a character to the end of the URL - making it out of sync with what the base64 decoding is expecting.
Result looks like this -
https://*******.blob.core.windows.net/files/REPORTS/*****/SEISMIC_ACQUISITION/ACQUISITION_REPORT_APPENDIX4_DAY_LOGS_JD_201.pdf5
It is always a number 5 that is added to the end of the string.
Any ideas as to what is going on here?
This is the full code - there is nothing else going on.
All that is happening is sending a search query to Azure search and returning the urls of blobs/documents which match the search query. Azure returns a base64 string and I want to decode that to plain readable text.
The error is:
Exception calling "FromBase64String" with "1" argument(s): "Invalid length for a Base-64 char array or string."
At line:25 char:9
+ $bloburl = [System.Text.Encoding]::UTF8.GetString([System.Con ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FormatException
It occurs at the line where it converts from base64.