tags:

views:

639

answers:

1

This Wiki article on Base64 URL says

"For this reason, a modified Base64 for URL variant exists, where no padding '=' will be used, and the '+' and '/' characters of standard Base64 are respectively replaced by '-' and '_', so that using URL encoders/decoders is no longer necessary and has no impact on the length of the encoded value, leaving the same encoded form intact for use in relational databases, web forms, and object identifiers in general."

When I try and remove the padding using ASP.NET, I get an error when I get my query strings back. How can I account for the missing padding?

+2  A: 
string encoded = GetBase64FromQueryString();

encoded = encoded.PadRight(NextMultiple(encoded.length, 4), '=');
...
static int NextMultiple(int value, int multiple)
{
    int r = value % multiple
    return value + (r != 0 ? multiple - r : 0)
}
AnthonyWJones