java - What characters will never be in a tomcat/spring boot session id? -
in spring boot app, want pass combined variable 1 rest service, out through user interface, , through second rest service. accomplish this, want first rest service create 1 single string concatenating session id different string representing else, , separator value marking break between 2 strings, string combined = sessionid+separatorcharacter+someotherstring
. this, second rest service accept combined string @requestparam
, , decompose string session id , other value.
i use string.split()
split 2 parts of combined string using separator value, like:
string[] parts = string.split("separatorcharacter"); string sessionid = parts[0]; string someotherstring = parts[1];
but what characters can choose when creating marker separating 2 parts of string? combined string used url parameter, has able cross internet in http
requests , never present in session id produced spring or tomcat. also, 1 of strings going base64 encoded, separator character needs survive encode/decode process. i decode before splitting, don't need worry characters used while encoded.
but, in case matters, encode/decode is:
import java.io.ioexception; import java.security.messagedigest; import java.security.nosuchalgorithmexception; import java.text.parseexception; import java.text.simpledateformat; import java.util.arraylist; import java.util.date; import java.util.list; import java.util.random; import sun.misc.base64decoder; import sun.misc.base64encoder; public class stringutil { private static random random = new random((new date()).gettime()); public static string encrypt(string userid) { base64encoder encoder = new base64encoder(); byte[] salt = new byte[8]; random.nextbytes(salt); return encoder.encode(salt)+encoder.encode(userid.getbytes()); } public static string decrypt(string encryptkey) { if (encryptkey.length() > 12) { string cipher = encryptkey.substring(12); base64decoder decoder = new base64decoder(); try { return new string(decoder.decodebuffer(cipher)); } catch (ioexception e) {} } return null; } }
Comments
Post a Comment