amuz.es/src/go/misc@v1.0.1/crypto/pkcs5.go (about) 1 package crypto 2 3 // Pkcs5pad is a padding function that uses the PKCS5 method. 4 func Pkcs5pad(data []byte, blocksize int) []byte { 5 pad := blocksize - len(data)%blocksize 6 b := make([]byte, pad, pad) 7 for i := 0; i < pad; i++ { 8 b[i] = uint8(pad) 9 } 10 return append(data, b...) 11 } 12 13 // Pkcs5unpad is a stripping function that reverts the PKCS5 method. 14 func Pkcs5unpad(data []byte) []byte { 15 pad := int(data[len(data)-1]) 16 // FIXME: check that the padding bytes are all what we expect 17 return data[:len(data)-pad] 18 }