Page 1 of 2

Decode url base64

Posted: Wed Aug 15, 2018 5:05 am
by burkulesomesh43
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.

Re: Decode url base64

Posted: Wed Aug 15, 2018 8:03 am
by ESP_Sprite
Possibly because what you have is not base64 encoded; it's urlencoded.

Re: Decode url base64

Posted: Wed Aug 15, 2018 12:57 pm
by burkulesomesh43
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??

Re: Decode url base64

Posted: Wed Aug 15, 2018 1:01 pm
by kolban
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.

Re: Decode url base64

Posted: Wed Aug 15, 2018 1:11 pm
by burkulesomesh43
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.

Re: Decode url base64

Posted: Wed Aug 15, 2018 3:34 pm
by burkulesomesh43
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??

Re: Decode url base64

Posted: Wed Aug 15, 2018 3:46 pm
by kolban
What source line is reporting the error?

Re: Decode url base64

Posted: Wed Aug 15, 2018 3:46 pm
by fly135
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

Re: Decode url base64

Posted: Wed Aug 15, 2018 3:53 pm
by burkulesomesh43
kolban wrote:What source line is reporting the error?
following line:
if(isxdigit(dStr[i+1]) && isxdigit(dStr[i+2]))

Re: Decode url base64

Posted: Wed Aug 15, 2018 4:03 pm
by fly135
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