Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 

Go Back   XSL - XML - RSS Forums > Programming and XML > Ruby on Rails and XML

Tags:



Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-02-2008, 12:01 AM
Kless
 
Posts: n/a

Default Base64 for URL variant



Does ruby core has any method to create a Base64 for URL variant?

---------
Using a URL-encoder on standard Base64, however, is inconvenient as it
will translate the '+' and '/' characters into special percent-encoded
hexadecimal sequences ('+' = '%2B' and '/' = '%2F'). When this is
later used with database storage or across heterogeneous systems, they
will themselves choke on the '%' character generated by URL-encoders
(because the '%' character is also used in ANSI SQL as a wildcard).

For this reason, a modified Base64 for URL variant exists, where no
padding '=' will be used, and the '+' and '/' characters of standard
Base64 are respectively replaced by '-' and '_', so that using URL
encoders/decoders is no longer necessary and has no impact on the
length of the encoded value, leaving the same encoded form intact for
use in relational databases, web forms, and object identifiers in
general.
---------
http://en.wikipedia.org/wiki/Base64
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-02-2008, 12:01 AM
ara.t.howard
 
Posts: n/a

Default Re: Base64 for URL variant


On Oct 1, 2008, at 3:33 PM, Kless wrote:

> Does ruby core has any method to create a Base64 for URL variant?




CGI.escape( Base64.encode( 'foobar' ) )

is one way...

a @ http://codeforpeople.com/
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Reply With Quote
  #3 (permalink)  
Old 10-02-2008, 12:01 AM
Rob Biedenharn
 
Posts: n/a

Default Re: Base64 for URL variant


On Oct 1, 2008, at 5:40 PM, ara.t.howard wrote:

>
> On Oct 1, 2008, at 3:33 PM, Kless wrote:
>
>> Does ruby core has any method to create a Base64 for URL variant?

>
>
>
> CGI.escape( Base64.encode( 'foobar' ) )
>
> is one way...
>
> a @ http://codeforpeople.com/
> --
> we can deny everything, except that we have the possibility of being
> better. simply reflect on that.
> h.h. the 14th dalai lama



Here's another:
# base64, but change + and / which are significant to URLs to -
and _,
# respectively, (which is what RFC4648 calls "base64url") and
remove
# embedded newlines (since they are recommended by MIME encoding
and not
# base64, per se)
encoded_token = [cipher_token].pack('m').tr('+/','-
_').gsub("\n",'')

the encoded_token is "safe" for a URL and the cipher_token is
retrieved with:

cipher_token = encoded_token.tr('-_','+/').unpack('m')[0]

The details of the cipher_token aren't important save that it can
contain any byte values.

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Contact Us -|- XSL - XML - RSS Forums -|- Archive -|- Top -|-Rules/Disclaimer-|-Help/Support -|-Advertise
© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
All times are GMT. The time now is 10:06 PM.
Style Developed by Epic Designz