The following code is not correctly encoding long strings to Base64. What can I do to fix this?
Input: The quick brown fox jumps over the lazy dog
Expected output: VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==
Actual output: VGhl
Param(
[string]$stringToEncode
)
$encoded = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($stringToEncode))
Write-Host $encoded
$stringToEncodeis not what you think it is (try adding aWrite-Debugand enabling debug output).The quick brown fox jumps over the lazy dog(without quotes) not as a single string"The quick brown fox jumps over the lazy dog"(with quotes). Thus onlyTheis passed into$stringToEncode(VGhl==The).