Your code works almost as expected. Itβs just that you somehow mixed the outputs of the Java version (and, possibly, the C # version).
If I execute your Java code (JDK 7 and 8 with Guava 18.0), I get
Ye-fySvneVUZJXth67-Si_e8fBUV4Sxs7wEXVDEOJjBMHl1encvt65gGIj8CiFzBGp5uUgKYJZCuQ4rc964vZigjlrJ_430LgYcathLLd9U
and if I execute your C # code ( DEMO ), I get
Ye-fySvneVUZJXth67-Si_e8fBUV4Sxs7wEXVDEOJjBMHl1encvt65gGIj8CiFzBGp5uUgKYJZCuQ4rc964vZigjlrJ_430LgYcathLLd9U1
So, the C # version has an extra β1β at the end. It should be a filling character, but it is not. This means that HttpServerUtility.UrlTokenEncode() does not provide standard compatibility with Base64 encoding, compatible with standards, and you should not use it. See also this Q & A.
Base64's secure encoding with URLs can easily be obtained from normal Base64 encoding (compare tables 1 and 2 in RFC4648), as shown in this answer from Mark Gravel:
string returnValue = System.Convert.ToBase64String(toEncodeAsBytes) .TrimEnd(padding).Replace('+', '-').Replace('/', '_');
with:
static readonly char[] padding = { '=' };
That is not all. If we take the Java output from
Ye + fySvneVUZJXth67 + Si / e8fBUV4Sxs7wEXVDEOJjBMHl1encvt65gGIj8CiFzBGp5uUgKYJZCuQ4rc964vZigjlrJ / 430LgYcathLLd9U =
and decrypt it, then we get the following token:
{"session_id": "4182e173-3a24-4c10-b76c-b85a36be1173", "ts_ms": 1445786965574}
which is different from the token you have in the code:
{'session_id': 'abf52ca5-9d87-4061-b109-334abb7e637a', 'ts_ms': 1445705791480}
The main problem is that you are using invalid JSON. Strings and keys in JSON must be wrapped in " rather than ' .
This means that the encrypted token should have been (using a valid version of the token from your code):
D9rOP07fYgBfza5vbGsvdPe8fBUV4Sxs7wEXVDEOJjBMHl1encvt65gGIj8CiFzBsAWBDgtdSozv4jS_auBU-CgjlrJ_430LgYcathLLd9U