From: Rob Biedenharn Date: 2008-10-02T07:08:33+09:00 Subject: 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