github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/smime/pad.go (about)

     1  package smime
     2  
     3  import "bytes"
     4  
     5  func pkcs7pad(data []byte) []byte {
     6  	blockSize := 16
     7  	padding := blockSize - len(data)%blockSize
     8  	padtext := bytes.Repeat([]byte{byte(padding)}, padding)
     9  	return append(data, padtext...)
    10  }
    11  
    12  func pkcs7unpad(data []byte) []byte {
    13  	length := len(data)
    14  	unpadding := int(data[length-1])
    15  	return data[:(length - unpadding)]
    16  }