I'm attempting to recreate a PKCS #5 Padding algorithm I've found written in python.
The main line I'm struggling to recreate is this
return data + (chr(pad_count) * pad_count).encode('utf-8')
which essentially repeats pad_count (an integer, between 1 and 16), as a char, between 1 and 16 times. I'm having trouble getting a similar result in Go.
For example, pad_count of 11 will return the string
\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b
The closeset I've come is this:
b := make([]byte, 2)
binary.LittleEndian.PutUint16(b, uint16(padCount))
fmt.Println("Pad: ", padCount, "Hex: ", hex.EncodeToString(b))
which will return:
Pad: 11 Hex: 0b00
This is pretty close, and obviously I could take a substring, and add the \x myself, but is there a better way to go about this? Also if I substring, I feel there is no guarantee that would work for all the combinations.