Skip to content

Instantly share code, notes, and snippets.

@he-and-her
Last active April 25, 2017 03:57
Show Gist options
  • Save he-and-her/01926f6cfa045d8e9f0bbf5ab2520635 to your computer and use it in GitHub Desktop.
Save he-and-her/01926f6cfa045d8e9f0bbf5ab2520635 to your computer and use it in GitHub Desktop.
decode session
key_generator = ActiveSupport::KeyGenerator.new(
Rails.application.config.secret_key_base,
iterations: 1000)
secret = key_generator.generate_key(
Rails.application.config
.action_dispatch
.encrypted_cookie_salt)
salt = key_generator.generate_key(
Rails.application.config
.action_dispatch
.encrypted_signed_cookie_salt)
encryptor = ActiveSupport::MessageEncryptor.new(
secret[
0,
ActiveSupport::MessageEncryptor.key_len
],
salt, serializer: JSON)
session_data
= encryptor.decrypt_and_verify(COOKIE_VALUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment