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

Yes, this is necessary to ensure different unique IDs are used when you sign a next certificate with this CA.
This number automatically increases when the appropriate openssl commands are issued.