The methods used use Base64 encoding to convert an encrypted byte array that can have all kinds of "non-printable" bytes into it - in a form that will contain only A - Z , A - Z , 0 - 9 , + , / and = .
However, these last 3 are not suitable for URLs.
You can make a simple String.Replace on a Base64 string by replacing these characters with URL-safe characters, for example. + => - , / => _ and = => . . You can even completely remove = from the end, as they only complement characters. (Performing the first two substitutions and reset = proposed by RFC3548 .)
Then just change this replacement when you want to decrypt the string. If you completely discard = , add = until the string is a multiple of 4.
source share