Decode url base64

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

Decode url base64

Postby burkulesomesh43 » Wed Aug 15, 2018 5:05 am

Hi,
I want to decode "ssid%40sss". this %40 has vale "@". when i am trying to decode "ssid%40sss" using mbedtls_base64_decode() function the processor gets reset again and again.
Here is my code...

unsigned char *decode_pass=NULL;
size_t len=32;
mbedtls_base64_decode(decode_pass, sizeof(decode_pass), &len,(unsigned char *) get_pass, strlen(get_pass));

can u please help me out.
--
Somesh Burkule

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: Decode url base64

Postby ESP_Sprite » Wed Aug 15, 2018 8:03 am

Possibly because what you have is not base64 encoded; it's urlencoded.

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

Re: Decode url base64

Postby burkulesomesh43 » Wed Aug 15, 2018 12:57 pm

ESP_Sprite wrote:Possibly because what you have is not base64 encoded; it's urlencoded.
ohh. I got it. it's my mistake. mbedtls function decodes base64 values not the url. thanks for reply.

but actually I want to decode url. Is there any function in esp idf which decodes URL??
--
Somesh Burkule

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Decode url base64

Postby kolban » Wed Aug 15, 2018 1:01 pm

There appear to be a number of C language routines on Github that claim to be URL decoders ... here is one that was posted 23 hours ago (from this date/time):

https://github.com/swarajsatvaya/UrlDecoder-C

But there appear to be many others.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

Re: Decode url base64

Postby burkulesomesh43 » Wed Aug 15, 2018 1:11 pm

kolban wrote:There appear to be a number of C language routines on Github that claim to be URL decoders ... here is one that was posted 23 hours ago (from this date/time):

https://github.com/swarajsatvaya/UrlDecoder-C

But there appear to be many others.
Thank you very much. very helpful for me. code also includes the substring finder function.
--
Somesh Burkule

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

Re: Decode url base64

Postby burkulesomesh43 » Wed Aug 15, 2018 3:34 pm

burkulesomesh43 wrote:
kolban wrote:There appear to be a number of C language routines on Github that claim to be URL decoders ... here is one that was posted 23 hours ago (from this date/time):

https://github.com/swarajsatvaya/UrlDecoder-C

But there appear to be many others.
Thank you very much. very helpful for me. code also includes the substring finder function.
I am using isxdigit() function given in ctype.h librairy.
but when i am calling this function it gives an error.

error: array subscript has type 'char'

char *urlDecode(const char *str) {

char *dStr = (char *) malloc(strlen(str) + 1);
char eStr[] = "00"; /* for a hex code */

strcpy(dStr, str);
int i; /* the counter for the string */

for(i=0;i<strlen(dStr);++i) {

if(dStr == '%') {
if(dStr[i+1] == 0)
return dStr;

if(isxdigit(dStr[i+1]) && isxdigit(dStr[i+2])) {

//d = 0;

/* combine the next to numbers into one */
eStr[0] = dStr[i+1];
eStr[1] = dStr[i+2];

/* convert it to decimal */
long int x = strtol(eStr, NULL, 16);

/* remove the hex */
memmove(&dStr[i+1], &dStr[i+3], strlen(&dStr[i+3])+1);

dStr = x;
}
}
else if(dStr == '+') { dStr = ' '; }
}
return dStr;
}

How to remove this error??
--
Somesh Burkule

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Decode url base64

Postby kolban » Wed Aug 15, 2018 3:46 pm

What source line is reporting the error?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Decode url base64

Postby fly135 » Wed Aug 15, 2018 3:46 pm

Quick search for "percent decoding c source" has lots of hits. This link has several suggested decoders in C.

https://stackoverflow.com/questions/267 ... ry/2766963

John A

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

Re: Decode url base64

Postby burkulesomesh43 » Wed Aug 15, 2018 3:53 pm

kolban wrote:What source line is reporting the error?
following line:
if(isxdigit(dStr[i+1]) && isxdigit(dStr[i+2]))
--
Somesh Burkule

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Decode url base64

Postby fly135 » Wed Aug 15, 2018 4:03 pm

kolban wrote:What source line is reporting the error?
He needs to cast the parameter in the isxdigit function call to an int.

Code: Select all

if(isxdigit((int)dStr[i+1]) && isxdigit((int)dStr[i+2]))
John A

Who is online

Users browsing this forum: Bing [Bot] and 126 guests