TG Telegram Group & Channel
Python Daily | United States America (US)
Create: Update:

Django PyCryptodome AES decryption - ValueError: Padding is incorrect

I am trying to encrypt incoming files and than decrypt them later. I was following the [documentation](https://www.pycryptodome.org/src/cipher/classic#cbc-mode) for how to use AES with CBC mode for decryption and encryption.

My view for uploading and encrypting file:

@router.post("/upload_files")
def upload_files(request, file: UploadedFile = File(...)):
save_file = operations.aes_encryption(user_id=request.auth.id,file=request.FILES.get('file'))

def aes_encryption(self,user_id,file):
user = UserQueries.get_user(id=user_id)
key: bytes = bytes(user.key, "utf-8")
path: str = user.path

save_file = self._encrypt_file(file,key,path,user)

return save_file

def _encrypt_file(self,file,key,path,user):
file_content = file.read()

cipher = AES.new(key, AES.MODE_CBC)


/r/django
https://redd.it/1c6cewm

Django PyCryptodome AES decryption - ValueError: Padding is incorrect

I am trying to encrypt incoming files and than decrypt them later. I was following the [documentation](https://www.pycryptodome.org/src/cipher/classic#cbc-mode) for how to use AES with CBC mode for decryption and encryption.

My view for uploading and encrypting file:

@router.post("/upload_files")
def upload_files(request, file: UploadedFile = File(...)):
save_file = operations.aes_encryption(user_id=request.auth.id,file=request.FILES.get('file'))

def aes_encryption(self,user_id,file):
user = UserQueries.get_user(id=user_id)
key: bytes = bytes(user.key, "utf-8")
path: str = user.path

save_file = self._encrypt_file(file,key,path,user)

return save_file

def _encrypt_file(self,file,key,path,user):
file_content = file.read()

cipher = AES.new(key, AES.MODE_CBC)


/r/django
https://redd.it/1c6cewm


>>Click here to continue<<

Python Daily






Share with your best friend
VIEW MORE

United States America Popular Telegram Group (US)