Decoding Facebook's signed request in Ruby/Sinatra
I've run into this before. You just need to pad the end of the payload string with =
marks until its length is divisible by 4.
This will work:
payload += '=' * (4 - payload.length.modulo(4))
(I'm not sure where/if this is documented by Facebook, but someone on IRC told me about it in early 2011, and sure enough, I've since found such padding in the source code of various Facebook client libraries)