为什么用cbc+pkcs7:(pkcs5是pkcs7固定8位)
python:S5542-Cipher Block Chaining (CBC) with PKCS#5 padding (or PKCS#7) is susceptible to padding oracle attacks.
偏移量:直接用key
python代码:
#!/usr/local/bin/python3
from Crypto.Cipher import AES
import os
import base64
class AESUtil:
__BLOCK_SIZE_16 = BLOCK_SIZE_16 = AES.block_size
@staticmethod
def encryt(enStr, key, iv):
cipher = AES.new(key, AES.MODE_CBC, iv)
x = AESUtil.__BLOCK_SIZE_16 - (len(enStr) % AESUtil.__BLOCK_SIZE_16)
if x != 0:
enStr = enStr + chr(x)*x
msg = cipher.encrypt(enStr)
msg = base64.b64encode(msg)
return str(msg, "utf-8")
@staticmethod
def decrypt(enStr, key, iv):
cipher = AES.new(key, AES.MODE_CBC, iv)
decryptByts = base64.b64decode(enStr)
msg = cipher.decrypt(decryptByts)
paddingLen = msg[len(msg)<