diff --git a/RNS/Cryptography/PKCS7.py b/RNS/Cryptography/PKCS7.py new file mode 100644 index 0000000..acffa63 --- /dev/null +++ b/RNS/Cryptography/PKCS7.py @@ -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] \ No newline at end of file