locked
Converting from Base64 RRS feed

  • Question

  • Hi,

    I'm currently pulling down a Base64 string from an API and converting the string into a file.

    $Base64 = [Convert]::FromBase64String($Data)
    [IO.File]::WriteAllBytes($File, $Data) 

    This has worked great but I recently came across a string that I couldn't convert and got the below error. 

    Unable to process Base64 string Exception calling "FromBase64String" with "1" argument(s): "The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters
    . "

    How do you go about troubleshooting this? When I plug the string into an online converter it doesn't give me any errors. The string doesn't have any header information.

    Thanks

    Monday, May 20, 2019 6:22 PM

Answers

  • You can't.  You have to start with a good string.  A bad string is just a bad string.

    You might check to see if the string is in an unsupported encoding like Unicode BE.  If it is than convert it first.


    \_(ツ)_/


    • Edited by jrv Monday, May 20, 2019 6:48 PM
    • Proposed as answer by Richard MuellerMVP Monday, May 20, 2019 7:46 PM
    • Marked as answer by RackHat Wednesday, May 22, 2019 1:30 PM
    Monday, May 20, 2019 6:46 PM

All replies

  • You can't.  You have to start with a good string.  A bad string is just a bad string.

    You might check to see if the string is in an unsupported encoding like Unicode BE.  If it is than convert it first.


    \_(ツ)_/


    • Edited by jrv Monday, May 20, 2019 6:48 PM
    • Proposed as answer by Richard MuellerMVP Monday, May 20, 2019 7:46 PM
    • Marked as answer by RackHat Wednesday, May 22, 2019 1:30 PM
    Monday, May 20, 2019 6:46 PM
  • Thanks, jrv. I will check to see if its encoded.
    Wednesday, May 22, 2019 1:32 PM