Skip to content

Instantly share code, notes, and snippets.

@mheyder
Last active January 11, 2019 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mheyder/f8117650da72059b00e046f823cc7bdd to your computer and use it in GitHub Desktop.
Save mheyder/f8117650da72059b00e046f823cc7bdd to your computer and use it in GitHub Desktop.
Rotate Rails 5.2 encrypted cookies key
Rails.application.config.action_dispatch.cookies_rotations.tap do |cookies|
salt = 'authenticated encrypted cookie'
encrypted_cookie_cipher = 'aes-256-gcm'
key_generator = ActiveSupport::KeyGenerator.new(ENV['OLD_SECRET_KEY_BASE'], iterations: 1000)
key_len = ActiveSupport::MessageEncryptor.key_len(encrypted_cookie_cipher)
secret = key_generator.generate_key(salt, key_len)
cookies.rotate :encrypted, secret
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment