i want to use cryptojs to encrypt cookies , i want to encrypt user id with his network card mac address.
cryptoJS needs to JSON.stringify this data then encrypts.
but i see this error in console:
TypeError: Converting circular structure to JSON
this is a snippet of my code:
var mac = 'e0:23:e3:46:57:52'
var userInfo = JSON.stringify({_id: user._id, mac: mac})
var cookie = crypto.AES.encrypt(userInfo, 'secret key')
res.cookie('userInfo', cookie, { expires: new Date(Date.now() + 900000000) })
user._id
is ObjectId
, just convert it to string:
var userInfo = JSON.stringify({ _id: user._id.toString(), mac: mac });
Also try to use util.inspect
, it automatically replaces circular links with [Circular]
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.