What encryption algorithm is best for encrypting cookies?

后端 未结 13 1110
感动是毒
感动是毒 2020-11-30 17:29

Since this question is rather popular, I thought it useful to give it an update.

Let me emphasise the correct answer as given by AviD to

13条回答
  •  一个人的身影
    2020-11-30 17:41

    You can achieve what you want securely by using AES in EAX mode. The ciphertext will be larger than the plaintext; that's normal for secure encryption.

    The attacker will of course know the length of your plaintext from the ciphertext, but they shouldn't be able to determine anything else.

    Generate AES keys randomly.

    Be sure and use a fresh nonce for each encryption, and use the "associated data" field to ensure that a thing you encrypted for one purpose isn't presented as being for another (so things like the user name and cookie name could go in there)

    the reactions below push toward: Do not trust encryption to accomplish security.

    More "if you're not an encryption expert you'll underestimate how easy it is to get wrong". For example, AFAICT no-one else in this thread has discussed chaining modes or message integrity, which covers two common beginner's mistakes.

提交回复
热议问题