Oct 082019
 
 October 8, 2019  Posted by at 7:05 am Azure, Azure Log Analytics  Add comments

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))

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

What is 6 + 9 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)