Some potential areas you may want to check:
- Use a single-byte encoding like ASCII or UTF-8.
-
Encode using base64url encoding, which replaces certain characters and discards padding.Actually, my current Server-to-Server OAuth implementation is using base64 encoding; it was JWT that used base64url encoding.
A .NET Framework / PowerShell compatible implementation for both of the above might be available via Microsoft.IdentityModel.Tokens.Base64UrlEncoder.Encode.