C
C#•8mo ago
McMahone

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
Pobiega
Pobiega•8mo ago
can you paste both string here?
canton7
canton7•8mo ago
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
Pobiega
Pobiega•8mo ago
yeah, and it doesnt change the result when deserialized
HtmlCompiler
HtmlCompiler•8mo ago
could be utf8 bom?
McMahone
McMahoneOP•8mo ago
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
Pobiega
Pobiega•8mo ago
No description
McMahone
McMahoneOP•8mo ago
Right, but my API only accepts the latter encoding. Is there anything different I can do to use the latter in my application?
HtmlCompiler
HtmlCompiler•8mo ago
if you enable strict mode you see an error also the longer base64 message has a CRLF (aka newline) at the end
canton7
canton7•8mo ago
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 end
McMahone
McMahoneOP•8mo ago
Ahh, I see. Thank you guys😊
Want results from more Discord servers?
Add your server