C
C#•2mo 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•2mo ago
can you paste both string here?
canton7
canton7•2mo 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•2mo ago
yeah, and it doesnt change the result when deserialized
ffmpeg -i me -f null -
could be utf8 bom?
McMahone
McMahone•2mo 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•2mo ago
No description
McMahone
McMahone•2mo ago
Right, but my API only accepts the latter encoding. Is there anything different I can do to use the latter in my application?
ffmpeg -i me -f null -
if you enable strict mode you see an error also the longer base64 message has a CRLF (aka newline) at the end
canton7
canton7•2mo 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
McMahone•2mo ago
Ahh, I see. Thank you guys😊