ruby - Decode a signed cookie in rails? -


so have signed cookie has following value

ijvvvgdiow1puu44qkk5nfzzul9udnci--a3c3b748fd207ba1c537b590dd458b4855677146 

i need decode , following value

5otgh9miqn8bi94vyr_tvw 

i tried

base64.decode64(cookie_value.split('--').first) 

but gives me wrong value, adds these damn slashes in string end

"\"5otgh9miqn8bi94vyr_tvw\""  

but gives me wrong value, adds these damn slashes in string end with

"\"5otgh9miqn8bi94vyr_tvw\""

its not adding slashes. issue here returned string included between double quotes ". \" here escape character.

here:

base64.decode64 "ijvvvgdiow1puu44qkk5nfzzul9udnci" # => "\"5otgh9miqn8bi94vyr_tvw\"" puts base64.decode64 "ijvvvgdiow1puu44qkk5nfzzul9udnci" # "5otgh9miqn8bi94vyr_tvw" 

as problem unwanted "s. can remove them follows:

base64.decode64(cookie_value.split('--').first).chomp('"').reverse.chomp('"').reverse # => "5otgh9miqn8bi94vyr_tvw" 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -