base64 encoding csv string
Hi, currently working with encoding a csv string file to base64, but Convert.Tobase64String gives different result than the base64 extension I use on Vscode. The method adds extra characters and two "=" at the end for padding. The extension from the Vscode is the correct one for my application, which only adds single "=" at the end without adding three extea characters (Both in UTF-8 format)
Am I doing something wrong or is it possible to encode in different ways?
11 Replies
can you paste both string here?
Yeah, "extra characters" doesn't give us much to go on
The amount of padding will be related to the number of characters, so that's probably just a secondary thing
yeah, and it doesnt change the result when deserialized
could be utf8 bom?
csv: company;project_no;project_job_no;project_job_name;project_job_status;responsible
001;1234;123;test;ACTIVE;999. Convert.ToBase64String(Encoding.UTF8.GetBytes(csv)) returns:Y29tcGFueTtwcm9qZWN0X25vO3Byb2plY3Rfam9iX25vO3Byb2plY3Rfam9iX25hbWU7cHJvamVjdF9qb2Jfc3RhdHVzO3Jlc3BvbnNpYmxlDQowMDE7MTIzNDsxMjM7dGVzdDtBQ1RJVkU7OTk5DQo=
with Base64 extension from VS Code: Y29tcGFueTtwcm9qZWN0X25vO3Byb2plY3Rfam9iX25vO3Byb2plY3Rfam9iX25hbWU7cHJvamVjdF9qb2Jfc3RhdHVzO3Jlc3BvbnNpYmxlDQowMDE7MTIzNDsxMjM7dGVzdDtBQ1RJVkU7OTk5
This is a different example the ToBase64 adds extra characters while the vscode version does not, but decoding returns the same csv string
as you can see here, they contain the exact same information
https://gchq.github.io/CyberChef/#recipe=From_Base64('A-Za-z0-9%2B/%3D',true,false)&input=WTI5dGNHRnVlVHR3Y205cVpXTjBYMjV2TzNCeWIycGxZM1JmYW05aVgyNXZPM0J5YjJwbFkzUmZhbTlpWDI1aGJXVTdjSEp2YW1WamRGOXFiMkpmYzNSaGRIVnpPM0psYzNCdmJuTnBZbXhsRFFvd01ERTdNVEl6TkRzeE1qTTdkR1Z6ZER0QlExUkpWa1U3T1RrNURRbz0KClkyOXRjR0Z1ZVR0d2NtOXFaV04wWDI1dk8zQnliMnBsWTNSZmFtOWlYMjV2TzNCeWIycGxZM1JmYW05aVgyNWhiV1U3Y0hKdmFtVmpkRjlxYjJKZmMzUmhkSFZ6TzNKbGMzQnZibk5wWW14bERRb3dNREU3TVRJek5Ec3hNak03ZEdWemREdEJRMVJKVmtVN09UazU&oeol=CRLF
cyberchef link included
Right, but my API only accepts the latter encoding. Is there anything different I can do to use the latter in my application?
if you enable strict mode you see an error
also the longer base64 message has a CRLF (aka newline) at the end
Yep, that's the only difference by the looks of it
@McMahone Make sure the thing you're encoding with
ToBase64
doesn't have a newline at the endAhh, I see. Thank you guys😊