Changeset 36 for trunk/lib/bletchley/buffertools.py
- Timestamp:
- 02/12/13 15:47:25 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/bletchley/buffertools.py
r18 r36 122 122 return chr(length) * length 123 123 124 def stripPKCS7Pad(decrypted, block_size=16 ):124 def stripPKCS7Pad(decrypted, block_size=16, log_file=None): 125 125 ''' 126 126 Validates a plaintext containing a PKCS5/7 pad, then returns the plaintext … … 128 128 ''' 129 129 if len(decrypted) % block_size != 0: 130 if log_file: 131 log_file.write("Can't strip PKCS7 pad. Plaintext not correct length\n") 130 132 return None 131 133 132 134 length = ord(decrypted[-1]) 133 135 if length > block_size: 136 if log_file: 137 log_file.write("Can't strip PKCS7 pad. Final byte length (%d) too large.\n" % length) 134 138 return None 135 139 136 if decrypted[0-length:] != pkcs7Pad(length): 140 pad = decrypted[0-length:] 141 if pad != pkcs7Pad(length): 142 if log_file: 143 log_file.write("Can't strip PKCS7 pad. Pads don't match. (%s != %s)\n" % (repr(pad), repr(pkcs7Pad(length)))) 137 144 return None 138 145
Note: See TracChangeset
for help on using the changeset viewer.