Iris Classon
Iris Classon - In Love with Code

Padding base64 strings in Kusto before decoding

base64 padding kusto

It’s been a while since I’ve last shared some hacky Kusto code, but today I have some for you. A while back I shared how you can decode base64, and it generally works fine. But, as you might have noticed, sometimes the bas64 payload won’t be correctly decoded with the built-in base64 decoder in Kusto (or .NET etc). In code I usually use the modulus operator to see if I need to append some padding to the encoded string. You can do the same with Kusto, although I’m sure my code can be refactored a little bit hehe. Nonetheless, here is another hacky gem from your full-hack developer Iris :)

 let decodedPayload = (payload:string)
{
   base64_decodestring(tostring(payload));
};
let base64Fix = (str:string)
{
   let b1 = iff(strlen(str)%4==0,str,strcat(str,'='));
   let b2 = iff(strlen(b1)%4==0,b1,strcat(str,'=='));
   b2
};
let base64 = 'somethingbase64';
print decodedPayload(base64Fix(base64))

Comments

Leave a comment below, or by email.


Last modified on 2019-10-08

comments powered by Disqus