It doesn't really matter as usual, but usually Base64 should work well.
Warning note:
It looks like you want to save arbitrary settings in a cookie. This is usually not a good idea, because cookies (like all client inputs) are not trusted. Consider storing server-side data under some generated (random!) Identifier and placed in a cookie. Thus, people cannot bypass access restrictions or enter arbitrary data into your system using processed cookies.
If you cannot use this approach, treat the cookie values as an untrusted input and check it as usual.
Edit:
Base64 is not suitable as it uses "=" which Java cookies do not support. Use more likely
java.net.URLEncoder.encode
which uses only cookie matching characters.
sleske
source share