Information Security Stack Exchange is a question and answer site for information security professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to store some user's security information in cookie, but I want to encrypt it so that nobody can see what is really inside it.

And when client makes request, I want to decrypt it. What mechanism I can use to achieve this provided I cannot store the "key" used to encrypt as I have stateless mechanism between client and server, so i cannot store the key somewhere in session.


share|improve this question
I guess you are looking for a master key which you use to generate the actual encryption keys used for the encryption. This master key should be somehow accessible from your app code (or your app could handle the payload further to be decrypted). – timoh Apr 25 '14 at 12:47
Are replay attacks and/or known-plaintext attacks an issue in your scenario? – Philipp Apr 25 '14 at 13:28

You want your server to be able to decrypt the data, and nobody else. Therefore, your server must "know" something that other people do not, and that "something" is what cryptographers call a key.

However, there is no need for that key to be specific to the user. It can be a server-wide key. With symmetric encryption, the key to encrypt and the key to decrypt are the same; this will work for you if your server is also the system which does the encryption (since cookie values are set by the server, I suppose that this is your situation).

Some notes:

  1. You want integrity too. In your system, the user is a potential attacker. The cookie is on his machine, so he could try to alter it. Encryption will prevent him from knowing the contents, but he may still make some "guesses" and alter it. Encryption does not ensure integrity by itself.

  2. Combining encryption and integrity is not as easy as it seems. See this question for theory and pointers on the subject.

  3. The server-wide key is sensitive information; manage it sensibly. In particular, you don't want to push it to all your backups (because lost/stolen backup tapes or disks are a classic leak mechanism), but you don't want to lose it either.

share|improve this answer
Thomas, the downside for using one key for everybody would be that if attacker gets to know, it would compromise the entire user base ? – Novice User Apr 26 '14 at 2:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.