Skip to content

Instantly share code, notes, and snippets.



Forked from fideloper/
Last active Nov 8, 2020
What would you like to do?
Decrypt Laravel-encrypted value
# Python3 code below
import os
import base64
import json
from Crypto.Cipher import AES
from phpserialize import loads
import hashlib
import hmac
def decrypt(payload):
data = json.loads(base64.b64decode(payload))
if not valid_mac(key, data):
return None
value = base64.b64decode(data['value'])
iv = base64.b64decode(data['iv'])
return unserialize(mcrypt_decrypt(value, iv, key))
def mcrypt_decrypt(value, iv, key):
return crypt_object.decrypt(value)
def unserialize(serialized):
return loads(serialized)
def valid_mac(key, payload):
dig =, digestmod=hashlib.sha256)
dig = dig.hexdigest()
return dig==payload['mac']

This comment has been minimized.

Copy link

@shamimulalam shamimulalam commented Apr 13, 2020

Traceback (most recent call last):
File "/var/www/html/adnsms/SMS-Shooting-Process/Helpers/", line 40, in
File "/var/www/html/adnsms/SMS-Shooting-Process/Helpers/", line 19, in decrypt
return mcrypt_decrypt(value, iv, key)
File "/var/www/html/adnsms/SMS-Shooting-Process/Helpers/", line 24, in mcrypt_decrypt,mode=AES.MODE_CBC,IV=iv)
File "/var/www/html/adnsms/SMS-Shooting-Process/venv/lib/python3.8/site-packages/Crypto/Cipher/", line 234, in new
return _create_cipher(sys.modules[name], key, mode, *args, **kwargs)
File "/var/www/html/adnsms/SMS-Shooting-Process/venv/lib/python3.8/site-packages/Crypto/Cipher/", line 79, in _create_cipher
return modes[mode](factory, **kwargs)
File "/var/www/html/adnsms/SMS-Shooting-Process/venv/lib/python3.8/site-packages/Crypto/Cipher/", line 274, in _create_cbc_cipher
cipher_state = factory._create_base_cipher(kwargs)
File "/var/www/html/adnsms/SMS-Shooting-Process/venv/lib/python3.8/site-packages/Crypto/Cipher/", line 92, in _create_base_cipher
if len(key) not in key_size:
TypeError: argument of type 'int' is not iterable

Hey Orian, I'm getting this error while trying to decrypt. Can you help me out please ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment