Skip to content

Instantly share code, notes, and snippets.

View petitJAM's full-sized avatar
🤖
beep boop Androids

Alex Petitjean petitJAM

🤖
beep boop Androids
View GitHub Profile
@petitJAM
petitJAM / with_active_support.rb
Created March 20, 2018 22:07 — forked from mbyczkowski/with_active_support.rb
session cookie decrypter for Rails 4.2+
require 'cgi'
require 'json'
require 'active_support'
def verify_and_decrypt_session_cookie(cookie, secret_key_base)
cookie = CGI::unescape(cookie)
salt = 'encrypted cookie'
signed_salt = 'signed encrypted cookie'
key_generator = ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000)
secret = key_generator.generate_key(salt)[0, ActiveSupport::MessageEncryptor.key_len]