Skip to content

Instantly share code, notes, and snippets.

@dedfft
Forked from fideloper/crypt.py
Created October 6, 2021 16:21
Show Gist options
  • Save dedfft/f919a73b6a6564165ad3b156b7cd77a7 to your computer and use it in GitHub Desktop.
Save dedfft/f919a73b6a6564165ad3b156b7cd77a7 to your computer and use it in GitHub Desktop.
Decrypt Laravel-encrypted value
import os
import base64
import json
from Crypto.Cipher import AES
from phpserialize import loads
def decrypt(payload):
data = json.loads(base64.b64decode(payload))
value = base64.b64decode(data['value'])
iv = base64.b64decode(data['iv'])
return unserialize(mcrypt_decrypt(value, iv))
def mcrypt_decrypt(value, iv):
AES.key_size=128
key=os.environ['APP_KEY']
crypt_object=AES.new(key=key,mode=AES.MODE_CBC,IV=iv)
return crypt_object.decrypt(value)
def unserialize(serialized):
return loads(serialized)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment