473,568 Members | 2,850 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

base64 in url allways safe ?


I am using the two functions below to encode part of a url. I had seen
that someone said base64 can sometimes add newlines in the encoding,
but had little luck finding reference to that using google, but I want
to make sure I am safe.
my url looks like this:
http://my.local/index.php/widget/fil...2F0ZWRfbmV3cy9

// functions to code url segments ...
function base64_url_enco de($input) {
return strtr(base64_en code($input), '+/=', '-_.');
}

function base64_url_deco de($input) {
return base64_decode(s trtr($input, '-_.', '+/='));
}

Jun 27 '08 #1
5 6853
wb*******@yahoo .com wrote:
I am using the two functions below to encode part of a url. I had seen
that someone said base64 can sometimes add newlines in the encoding,
but had little luck finding reference to that using google, but I want
to make sure I am safe.
my url looks like this:
http://my.local/index.php/widget/fil...2F0ZWRfbmV3cy9

// functions to code url segments ...
function base64_url_enco de($input) {
return strtr(base64_en code($input), '+/=', '-_.');
}

function base64_url_deco de($input) {
return base64_decode(s trtr($input, '-_.', '+/='));
}

I haven't seen any base64 implementations which use a newline character
- and I doubt there are any (it's not a printable character).

But rather then use strstr, just urlencode the results from
base64_encode() .

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Jun 27 '08 #2
On Jun 6, 3:34 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
wbsurf...@yahoo .com wrote:
I am using the two functions below to encode part of a url. I had seen
that someone said base64 can sometimes add newlines in the encoding,
but had little luck finding reference to that using google, but I want
to make sure I am safe.
my url looks like this:
http://my.local/index.php/widget/fil.../aHR0cDovL21lZ...
// functions to code url segments ...
function base64_url_enco de($input) {
return strtr(base64_en code($input), '+/=', '-_.');
}
function base64_url_deco de($input) {
return base64_decode(s trtr($input, '-_.', '+/='));
}

I haven't seen any base64 implementations which use a newline character
- and I doubt there are any (it's not a printable character).

But rather then use strstr, just urlencode the results from
base64_encode() .

uuencode does it (presumably because it was written when line-oriented
terminals were the common way of interacting with data) and MIME does
it (because SMTP is line oriented). But AFAIK the php implementation
doesn't.

It's a handy way to move data around because:
$enc=str_replac e('=','', base64_encode($ data)); // the trailing '=='
is not required
urlencode($enc) === mysql_real_esca pe($enc) === htmlentities($e nc)
=== addslashes($enc ) === stripslashes($e nc) === $enc

C.
Jun 27 '08 #3
C. (http://symcbean.blogspot.com/) wrote:
On Jun 6, 3:34 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>wbsurf...@yaho o.com wrote:
>>I am using the two functions below to encode part of a url. I had seen
that someone said base64 can sometimes add newlines in the encoding,
but had little luck finding reference to that using google, but I want
to make sure I am safe.
my url looks like this:
http://my.local/index.php/widget/fil.../aHR0cDovL21lZ...
// functions to code url segments ...
function base64_url_enco de($input) {
return strtr(base64_en code($input), '+/=', '-_.');
}
function base64_url_deco de($input) {
return base64_decode(s trtr($input, '-_.', '+/='));
}
I haven't seen any base64 implementations which use a newline character
- and I doubt there are any (it's not a printable character).

But rather then use strstr, just urlencode the results from
base64_encode( ).

uuencode does it (presumably because it was written when line-oriented
terminals were the common way of interacting with data) and MIME does
it (because SMTP is line oriented). But AFAIK the php implementation
doesn't.

It's a handy way to move data around because:
$enc=str_replac e('=','', base64_encode($ data)); // the trailing '=='
is not required
urlencode($enc) === mysql_real_esca pe($enc) === htmlentities($e nc)
=== addslashes($enc ) === stripslashes($e nc) === $enc

C.
Yes, that's a different way to do it. I've always used base64_encode,
mostly out of habit.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Jun 27 '08 #4
Jerry Stuckle wrote:
C. (http://symcbean.blogspot.com/) wrote:
>On Jun 6, 3:34 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>>wbsurf...@yah oo.com wrote:
I am using the two functions below to encode part of a url. I had seen
that someone said base64 can sometimes add newlines in the encoding,
but had little luck finding reference to that using google, but I want
to make sure I am safe.
my url looks like this:
http://my.local/index.php/widget/fil.../aHR0cDovL21lZ...

// functions to code url segments ...
function base64_url_enco de($input) {
return strtr(base64_en code($input), '+/=', '-_.');
}
function base64_url_deco de($input) {
return base64_decode(s trtr($input, '-_.', '+/='));
}
I haven't seen any base64 implementations which use a newline character
- and I doubt there are any (it's not a printable character).

But rather then use strstr, just urlencode the results from
base64_encode ().

uuencode does it (presumably because it was written when line-oriented
terminals were the common way of interacting with data) and MIME does
it (because SMTP is line oriented). But AFAIK the php implementation
doesn't.

It's a handy way to move data around because:
$enc=str_replac e('=','', base64_encode($ data)); // the trailing '=='
is not required
urlencode($enc) === mysql_real_esca pe($enc) === htmlentities($e nc)
=== addslashes($enc ) === stripslashes($e nc) === $enc

C.

Yes, that's a different way to do it. I've always used base64_encode,
mostly out of habit.
the base64_encode function will never add any newline to result string,
but in the description of RFC 2045, base64ed string should be splited by
\r\n every 76 characters.
Jun 27 '08 #5
GuangXiN wrote:
Jerry Stuckle wrote:
>C. (http://symcbean.blogspot.com/) wrote:
>>On Jun 6, 3:34 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
wbsurf...@ya hoo.com wrote:
I am using the two functions below to encode part of a url. I had seen
that someone said base64 can sometimes add newlines in the encoding,
but had little luck finding reference to that using google, but I want
to make sure I am safe.
my url looks like this:
http://my.local/index.php/widget/fil.../aHR0cDovL21lZ...
>
// functions to code url segments ...
function base64_url_enco de($input) {
return strtr(base64_en code($input), '+/=', '-_.');
}
function base64_url_deco de($input) {
return base64_decode(s trtr($input, '-_.', '+/='));
}
I haven't seen any base64 implementations which use a newline character
- and I doubt there are any (it's not a printable character).

But rather then use strstr, just urlencode the results from
base64_encod e().
uuencode does it (presumably because it was written when line-oriented
terminals were the common way of interacting with data) and MIME does
it (because SMTP is line oriented). But AFAIK the php implementation
doesn't.

It's a handy way to move data around because:
$enc=str_replac e('=','', base64_encode($ data)); // the trailing '=='
is not required
urlencode($enc) === mysql_real_esca pe($enc) === htmlentities($e nc)
=== addslashes($enc ) === stripslashes($e nc) === $enc

C.

Yes, that's a different way to do it. I've always used base64_encode,
mostly out of habit.

the base64_encode function will never add any newline to result string,
but in the description of RFC 2045, base64ed string should be splited by
\r\n every 76 characters.
This RFC is discussing how to use bas64 encoding in email - which has
absolutely nothing to do with the topic at hand.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5384
by: wenmang | last post by:
Hi, I ma thinking whether to use Base64 encoding to encode the binary content in the XML file. I have done some simple calculations, it seems to me that the size for encoded content increases by ~30%, is this the drawback for using the encoding scheme? Thanks.
5
4943
by: Rasmus | last post by:
In a asp.net site i need to make a url link like this: http://server.com/test.aspx?base64=c+KAnMOfxZLDqhd2w4DCtMOmwr8hawkCdsK9YH7igqwITuKAmcOhXAcDxbjFoR3Cum/DqwFJRU7DpzbigJlYZD1cJcKBwqgaBsObw6VxMMW9wrTDpD7CpSTDkeKAuuKAlFfDt8W+Jz3CvhM7w5HCjeKAneKAuT3Dn8WTw5zigKErw6QFxaF+wrvDksOkwqjDq1fCrsOewrc= I've used the Convert.ToBase64String() to make the...
5
20935
by: Rasmus | last post by:
In a asp.net site i need to make a url link like this: http://server.com/test.aspx?base64=c+KAnMOfxZLDqhd2w4DCtMOmwr8hawkCdsK9YH7igqwITuKAmcOhXAcDxbjFoR3Cum/DqwFJRU7DpzbigJlYZD1cJcKBwqgaBsObw6VxMMW9wrTDpD7CpSTDkeKAuuKAlFfDt8W+Jz3CvhM7w5HCjeKAneKAuT3Dn8WTw5zigKErw6QFxaF+wrvDksOkwqjDq1fCrsOewrc= I've used the Convert.ToBase64String() to make the...
26
2344
by: Jim Brandley | last post by:
I need to append a short ciphertext string as a query variable encoded so it's valid for a URL. After encryption, I convert the bytes to Base64. However, the result includes characters that are invalid for a URL, notably '+' symbols. So, I have to cycle the output string through HttpUtility.UrlEncode(). That takes time. I wrote my own URL-safe...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7916
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8117
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7660
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2101
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.