Decode url base64
-
- Posts: 132
- Joined: Tue Aug 14, 2018 6:21 am
- Location: India
Decode url base64
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.
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
Somesh Burkule
-
- Posts: 9764
- Joined: Thu Nov 26, 2015 4:08 am
Re: Decode url base64
Possibly because what you have is not base64 encoded; it's urlencoded.
-
- Posts: 132
- Joined: Tue Aug 14, 2018 6:21 am
- Location: India
Re: Decode url base64
ohh. I got it. it's my mistake. mbedtls function decodes base64 values not the url. thanks for reply.ESP_Sprite wrote:Possibly because what you have is not base64 encoded; it's urlencoded.
but actually I want to decode url. Is there any function in esp idf which decodes URL??
--
Somesh Burkule
Somesh Burkule
Re: Decode url base64
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.
https://github.com/swarajsatvaya/UrlDecoder-C
But there appear to be many others.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
-
- Posts: 132
- Joined: Tue Aug 14, 2018 6:21 am
- Location: India
Re: Decode url base64
Thank you very much. very helpful for me. code also includes the substring finder function.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.
--
Somesh Burkule
Somesh Burkule
-
- Posts: 132
- Joined: Tue Aug 14, 2018 6:21 am
- Location: India
Re: Decode url base64
I am using isxdigit() function given in ctype.h librairy.burkulesomesh43 wrote:Thank you very much. very helpful for me. code also includes the substring finder function.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.
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
Somesh Burkule
Re: Decode url base64
What source line is reporting the error?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: Decode url base64
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
https://stackoverflow.com/questions/267 ... ry/2766963
John A
-
- Posts: 132
- Joined: Tue Aug 14, 2018 6:21 am
- Location: India
Re: Decode url base64
following line:kolban wrote:What source line is reporting the error?
if(isxdigit(dStr[i+1]) && isxdigit(dStr[i+2]))
--
Somesh Burkule
Somesh Burkule
Re: Decode url base64
He needs to cast the parameter in the isxdigit function call to an int.kolban wrote:What source line is reporting the error?
Code: Select all
if(isxdigit((int)dStr[i+1]) && isxdigit((int)dStr[i+2]))
Who is online
Users browsing this forum: Bing [Bot] and 120 guests