现在很多人推崇客户端的Session,主要场景是用在各种APP的服务器端上,优点是服务器Scale的时候不需要同步客户端的session,多少台服务器都无所谓
也很明显,客户端总是不安全的,即便是加密了Cookie数据,但既然是可以被服务器端解密的,那么其他人也可以通过分析大量的加密后数据进行算法猜测,是有可能被破解的。
Not a good idea
``` Not a good idea. Storing vital data like session expiry and user name entirely on client side is too dangerous IMO, encrypted or not. Even if the concept is technically safe in itself (I can’t answer that in depth, I’m no encryption expert), a break-in could be facilitated without compromising your server, just by acquiring your encryption key.
Somebody who gets hold of the key could generate session cookies at will, impersonating any user for any length of time, something the classical session concept is designed to prevent.
There are better and scalable solutions for this problem. Why not, for instance, set up a central session verification instance that all associated servers and services can poll? Look around on the web, I am 100% sure there are ready-made solutions addressing your needs. ```
公钥
私钥
进行加密 公钥
进行解密,读取其中的数据,并且将加密后的数据存在本地Cookie