Created
June 10, 2013 20:15
-
-
Save dmichael/5751886 to your computer and use it in GitHub Desktop.
Unpad a PKCS7 pad from a block cipher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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