Some values are stored in cookies after base64 encoding. When there is one or two equal signs (=) at the end of the encoded string, request is used. getcookies (). getvalue () will lose the equal sign and cause an error when base64 decoding is performed.
Https://issues.apache.org/bugzilla/show_bug.cgi? Id = 44679. You can see the discussion in this link.
It mentioned:
Org. Apache. tomcat. util. http. servercookie.Allow_equals_in_value
System Property
That was introduced in Tomcat 6.0.24. Looks like Mark has seen the light.
I just wanted to update this issue so everyone that needs this feature is aware
Of It.
Solution:
1) directly retrieve the cookie value from the HTTP head, resolve it by yourself, and keep the equal sign in the value. (cookie value format: Name = value; name2 = value2; name3 = value3
2) Before base64 decoding, calculate the length and supplement the equal sign before decoding.
Public static string decodebase64 (string s) {Switch (S. length () % 4) {Case 3: S + = "="; break; // Note: you only need to add one or two equal signs, case 2: S + = "="; break; Case 1: S + = "="; break; default :} return new base64encoder (). decode (S. getbytes ();} public static string encodebase64 (string s) {string encoded = base64encoder (). encode (S. getbytes (); Return encoded. replaceall ("[\ n =]", "");}
Note:
Cookie specifications