I have encountered an issue with BinaryToBase64 when trying to encrypt and decrypt input parameters on a screen.
Firstly, I use AES_Encrypt to encrypt the input parameter on the screen. Secondly, I convert the binary cipher to base64. This is necessary to pass it as an input parameter to the screen. In the OnInitialize on the screen, I call "Base64ToBinary", as I need to convert the input parameter back to binary before I pass it to AES_Decrypt.
When I call "Base64ToBinary", it throws an error, stating: 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.
I use LogMessage to output the Base64 string, and it contains a white space in the middle of the string: lqBcw3xk5AS LyZMSKz1pXtVoRA58jk36tT85tP7sIeSNrS6iPPm2EVzdWj3E6QhR5HnywjHYNUxjPRR7roa4A==.
White space is not an allowed character. If I remove the white space, the string is no longer a multiple of 4 (87 characters long). If I remove one or two of the padding characters, the string is not a multiple of 4 (85 or 86 characters).
As a result, BinaryToBase64 has made a string that cannot be converted back to binary. Has anyone experienced this?
Edit: I compared the string before and after its passed as an input parameter to the screen. It does not contain any white space after being converted to Base64 from binary (before passing it as an input to screen). When I try to convert the input parameter to binary, it suddenly contains a white space.
I found the problem. When the string is passed as an input to the screen, it replaces the "+"-characters with white space. URLEncode should probable fix the issue
Hi @Anders Stene
Try to Remove white space and add the padding (=) in last.
in your case add == in last
Regards ,
Rajat
Hi,
If I remove the white space from a string that is 88 characters long, the string is 87 characters long. In my example, binaryToBase64 has already added two padding characters (=), which means I cannot add anymore. If I remove one or two of the padding, the string is 86 or 85 characters long. This is also the wrong length.
Example string: lqBcw3xk5AS LyZMSKz1pXtVoRA58jk36tT85tP7sIeSNrS6iPPm2EVzdWj3E6QhR5HnywjHYNUxjPRR7roa4A==
could you please share your original Base64 String.
It is the one in the example:
lqBcw3xk5AS LyZMSKz1pXtVoRA58jk36tT85tP7sIeSNrS6iPPm2EVzdWj3E6QhR5HnywjHYNUxjPRR7roa4A==
There is a white space between "lqBcw3xk5AS" and "LyZMSKz1pXtVoRA58jk36tT85tP7sIeSNrS6iPPm2EVzdWj3E6QhR5HnywjHYNUxjPRR7roa4A=="