Added python-only implementation of PKCS7 padding

This commit is contained in:
Mark Qvist 2022-06-07 17:32:22 +02:00
parent 19a033db96
commit b2b6708e8f

18
RNS/Cryptography/PKCS7.py Normal file
View File

@ -0,0 +1,18 @@
class PKCS7:
BLOCKSIZE = 16
@staticmethod
def pad(data, bs=BLOCKSIZE):
l = len(data)
n = bs-l%bs
v = bytes([n])
return data+v*n
@staticmethod
def unpad(data, bs=BLOCKSIZE):
l = len(data)
n = data[-1]
if n > bs:
raise ValueError("Cannot unpad, invalid padding length of "+str(n)+" bytes")
else:
return data[:l-n]