tls: Fix encoding handling in certificate-related functions (GH-8366)

Is this necessary?