From: Mark Hubbart Date: 2004-07-15T08:43:14+09:00 Subject: Re: How to encode binary for http.post() Oops. Sorry to reply to my own post. I made a mistake. On Jul 14, 2004, at 11:34 AM, Mark Hubbart wrote: > something like this: > > require 'base64' > => nil > def Base64.encode64url(str) > Base64.encode64(str).tr("+/","-_") > end > => nil > def Base64.decode64url(str) > Base64.decode64(str.tr("-_","+/")) > end > => nil > (data = (0..255).inject(""){|a,v|a< 255 > => 256 > (encoded = Base64.encode64url(data)).count "+/" # any prohibited > characters? > => 0 > # raise error if encoded data is incorrect > > => 0 the last line should be: x=0; Base64.decode64url(encoded).each_byte{|b| raise if x!=b; x=b+1}; 0 => 0 (I copied from various places in my testing window; I didn't check for consistency) cheers, Mark