2014-09-19

verify Rails 4.1 signed cookie from Ruby

de-code in

~/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/cookies.rb

and just code

class NullSerializer
  def self.load(value) ; value ; end
  def self.dump(value) ; value ; end
end
key_generator = ActiveSupport::KeyGenerator.new(
  #{rails secret_key_base here (config/secrets.yml)} ,
  iterations: 1000
)
secret = key_generator.generate_key("signed cookie") #default value of Rails 4.1
verifier = ActiveSupport::MessageVerifier.new(secret, serializer: NullSerializer)
cookie = CGI.unescape(#{single source string of cookie})
ans = verifier.verify(cookie)

沒有留言:

張貼留言