Skip to content

Instantly share code, notes, and snippets.

@dmichael
Created June 10, 2013 20:15
Show Gist options
  • Save dmichael/5751886 to your computer and use it in GitHub Desktop.
Save dmichael/5751886 to your computer and use it in GitHub Desktop.
Unpad a PKCS7 pad from a block cipher
// http://play.golang.org/p/YfMF5mG3v2
func UnPKCS7Padding(data []byte) []byte {
dataLen := len(data)
// Grab the last byte which is *always* the pad byte for the password implementation
endIndex := int(data[dataLen-1])
fmt.Println(data[dataLen-1])
if endIndex <= 16 {
if 1 < endIndex {
for i := dataLen - endIndex; i < dataLen; i++ {
if data[dataLen-1] != data[i] {
// Different byte codes, the tail byte code:
// bang
}
}
}
return data[:dataLen-endIndex]
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment