There is a variation of Base64 called Base64URL that’s essentially Base64 with tweaks to allow encoded strings in URLs without conflict. The following code will easily let you encode and decode this:
Public Shared Function EncodeBase64URL(value As String) as String
if value = "" then
return ""
end if
dim result as string = EncodeBase64( value )
result = ReplaceLineEndings( result, "" )
result = result.ReplaceAllB( "+", "-" )
result = result.ReplaceAllB( "/", "_" )
result = result.ReplaceAllB( "=", "" )
return result.DefineEncoding( Encodings.UTF8 )
End Function
Public Shared Function DecodeBase64URL(value As String) as String
if value = "" then
return ""
end if
value = value.ReplaceAllB( "-", "+" )
value = value.ReplaceAllB( "_", "/" )
//
// The native decoder doesn't care about the padding ("=") so
// we don't have to bother putting it back in
//
dim result as string = DecodeBase64( value )
return result
End Function
Enjoy.