Go decode ssl serial number

Viewed 73

I have ssl serial number 7b:c9:91:be:0b:be:08:2f:3a:97:60:84:f3:f8:4a:f2:d4:30:57:e2, binary encoded by other application in \u001c\ufffdدc\ufffd\u001e\ufffd\ufffd\ufffdN\ufffdhr\u001a\ufffd䶓\ufffd

How can I decode ssl serial number from binary to string view? Maybe there is a library or a set of functions for this?

1 Answers

For the most basic case you need something like this: https://go.dev/play/p/gp74V27lmAv

It goes over each byte of the binary encoded serial and converts it to hex. It separates the bytes with a ":" delimiter.

The code is an example and can be vastly improved, especially if you know how long those serials are. Then you can convert them with a single fmt.Sprintf() call by passing the individual bytes, e.g. fmt.Sprintf("%x:%x:%x:%x:%x:%x", b[0], b[1], b[2], b[3], b[4], b[5]) if your serial is 6 bytes long. You will obviously need to do all the relevant validation first.

Related