The documentation of ActionDispatch::Cookies
gives nearly identical descriptions for both signed cookies and encrypted cookies. It appears that both use secrets.secret_key_base
to prevent client-side tampering. http://api.rubyonrails.org/classes/ActionDispatch/Cookies.html
Signed Cookies
Sets a signed cookie, which prevents users from tampering with its value. The cookie is signed by your app's
secrets.secret_key_base
value. It can be read using the signed methodcookies.signed[:name]
cookies.signed[:user_id] = current_user.id
Encrypted cookies
Sets an encrypted cookie value before sending it to the client which prevent users from reading and tampering with its value. The cookie is signed by your app's
secrets.secret_key_base
value. It can be read using the encrypted methodcookies.encrypted[:name]
cookies.encrypted[:discount] = 45
My question is: What is the difference between the two?
When would you want to use one over the other?