admin管理员组

文章数量:1287596

I am using JQuery.cookies to manage cookies. I am storing objects and user/login informations.

Is there a way to encrypt or secure the cookies? or is it possible with SSL only?

I am using JQuery.cookies to manage cookies. I am storing objects and user/login informations.

Is there a way to encrypt or secure the cookies? or is it possible with SSL only?

Share Improve this question asked Dec 19, 2012 at 10:00 VuralVural 8,74611 gold badges42 silver badges58 bronze badges 4
  • Maybe with something like crypto.js. However JavaScript must be turned on otherwise it can't be used – bart s Commented Dec 19, 2012 at 10:02
  • The only thing I can think of is encrypting the data in the cookie. But this has to be done on the server-side for it to be secure. Encrypting on the client side is probably as insecure as just saving it as plain/text. Since the hacker will probably just reverse the process knowing all the variables. – Daniel Commented Dec 19, 2012 at 10:03
  • @Haris: No, with Javascript and JQuery – Vural Commented Dec 19, 2012 at 10:03
  • nice link:- nczonline/blog/2009/05/12/cookies-and-security – Pranav Commented Dec 19, 2012 at 10:04
Add a ment  | 

3 Answers 3

Reset to default 9

The usual way to secure cookies is by storing nothing but a randomly-generated session-id in them. The server keeps all sensitive information and associates them to the IDs it assigned to each visitor. This also has the advantage that you can store as much information as you want and are not bound to the space restriction of cookies.

This, of course, can not be done with Javascript alone. You will need server-sided programming for that.

You can simply store them as encrypted strings and once you retreive them then decrypt them. Any encryption with your secret key will do

Create a cookie with all available options along with the secure option.

$.cookie('myCookie', 'myValue', { expires: 365, secure: true });

secure {Boolean} If true, the secure attribute of the cookie will be set and the cookie transmission will require a secure protocol (like HTTPS).

本文标签: javascriptIs it possible to secure cookiesStack Overflow