Author Topic: Base64 decoding  (Read 6533 times)

Bamsen

  • Community Member
  • Posts: 66
  • Hero Points: 8
Base64 decoding
« on: April 12, 2019, 07:24:02 AM »
Hi,

I have a service that provides me with chunks of base64 encoded data.
Does anybody have a Slick-C script that can replace the selected base64 data with the clear text equivalent?

ex:
Code: [Select]
PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48YnJvd3NpbmdBY2NvdW50UGFzc3
 dvcmRTdGF0dXNTZXR0aW5ncyB4bWxuczp4c2Q9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2No
 ZW1hIiB4bWxuczp4c2k9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIi
 BkaXNwbGF5U3RhdHVzRW5hYmxlZD0idHJ1ZSIgYWNjb3VudEV4cGlyYXRpb25BZnRlckRheXM9Ijci
 IHBhc3N3b3JkRXhwaXJhdGlvbkFmdGVyRGF5cz0iMyIgZGlzcGxheVN0YXR1cz0iMTI3IiB4bWxucz
 0iaHR0cDovL3NvZnRlcnJhLmNvbS9hZGF4ZXMiIC8+
Is converted to:
Code: [Select]
<?xml version="1.0" encoding="utf-8"?><browsingAccountPasswordStatusSettings
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  displayStatusEnabled="true" accountExpirationAfterDays="7"
  passwordExpirationAfterDays="3" displayStatus="127"
  xmlns="http://softerra.com/adaxes"/>

---
Regards,
Morten

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: Base64 decoding
« Reply #1 on: April 12, 2019, 01:16:47 PM »
There doesn't seem to be anywhere in Slick-C that exposes an interface to encoding/decoding base64. 

If your platform has a command line tool to do the encoding/decoding, you could use filter-command to encode/decode selections.  For instance, on linux, there's a 'base64' command you can call out to.  Ex:

Code: [Select]
#pragma option(pedantic,on)
#include "slick.sh"
#import "util.e"

_command void b64_encode() name_info(',')
{
   filter_command('base64');
}

_command void b64_decode() name_info(',')
{
   filter_command('base64 -d');
}

With that loaded, you could select the text, and then run b64-decode to decode it.  If you're just decoding files that are all base64, you could add a call to `select_all()` in the b64_decode function so you don't have to do a manual selection.

Bamsen

  • Community Member
  • Posts: 66
  • Hero Points: 8
Re: Base64 decoding
« Reply #2 on: April 15, 2019, 07:02:42 AM »
Thank you!
That worked for my needs.  :)

---
Regards,
Morten