base64 string encoder/decoder

Post your feature requets for new triggers, conditions, actions and other improvements.

Moderator: Martin

Locked
elektroinside
Posts: 69
Joined: 14 Feb 2019 15:04

base64 string encoder/decoder

Post by elektroinside » 24 Apr 2019 13:12

Hi Martin,

Is is possible to add such a function to Automagic?

Thanks

elektroinside
Posts: 69
Joined: 14 Feb 2019 15:04

Re: base64 string encoder/decoder

Post by elektroinside » 24 Apr 2019 15:01

With padding would be great :)

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: base64 string encoder/decoder

Post by anuraag » 24 Apr 2019 17:00

Its possible using java function

define string variable.
replace DEFAULT with other option available here like NO_PADDING, NO_WRAP
//decode base64
decode=callJavaConstructor("java.lang.String", "String(byte[])", callJavaStaticMethod("android.util.Base64", "decode(java.lang.String, int)", string, getJavaStaticField("android.util.Base64", "DEFAULT")));

//encode to base64
encode=callJavaStaticMethod("android.util.Base64", "encodeToString(byte[], int)", callJavaMethod(string, "java.lang.String", "getBytes()"), getJavaStaticField("android.util.Base64", "DEFAULT"))

elektroinside
Posts: 69
Joined: 14 Feb 2019 15:04

Re: base64 string encoder/decoder

Post by elektroinside » 24 Apr 2019 17:11

Wow, it works perfectly!

Many thanks!

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: base64 string encoder/decoder

Post by Desmanto » 24 Apr 2019 17:44

Just about to answer this, and has been ninja'd by anuraag :D
But still +1 fo the encoding. Much easier to have built-in function for this.
If possible expand it to hex dec oct bin conversion too : viewtopic.php?f=5&t=7089
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

elektroinside
Posts: 69
Joined: 14 Feb 2019 15:04

Re: base64 string encoder/decoder

Post by elektroinside » 25 Apr 2019 05:20

"Ninja'd", haha :lol:

Locked