Created
May 9, 2017 17:32
-
-
Save mikeecb/84bfc914d0e1f6737889718ccff2446d to your computer and use it in GitHub Desktop.
Unpad Valid PKCS#7
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
def unpad_valid_pkcs7(buffer): | |
padding = buffer[-1] | |
for i in range(len(buffer)-1, len(buffer)-padding, -1): | |
if buffer[i] != buffer[-1]: | |
raise Exception("Bad PKCS#7 padding.") | |
new_buffer = bytearray() | |
new_buffer[:] = buffer[:-padding] | |
return new_buffer | |
unpad_valid_pkcs7(bytearray("ICE ICE BABY\x04\x04\x04\x03")) | |
Traceback (most recent call last): | |
File "15.py", line 10, in <module> | |
print unpad_valid_pkcs7(bytearray("ICE ICE BABY\x04\x04\x04\x03")) | |
File "15.py", line 5, in unpad_valid_pkcs7 | |
raise Exception("Bad PKCS#7 padding.") | |
Exception: Bad PKCS#7 padding. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment