-
-
Save fideloper/c4806c504e46e8cdb00a to your computer and use it in GitHub Desktop.
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) |
Hello ^_^
I am seeing this a bit later, but I was looking for this same thing and now that I have tried it it has problems with the "json.loads" part.
Here is the exception I am getting
Traceback (most recent call last):
File "C:\Users\PC\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws
invokeLocal\runtimeWrappers\invoke.py", line 86, in
result = handler(input['event'], context)
File ".\sendMail.py", line 52, in sendMailSMTP
print(decrypt(secret, app_key))
File ".\sendMail.py", line 98, in decrypt
data = json.loads(dataJson)
File "C:\Users\PC\Anaconda3\lib\json_init_.py", line 343, in loads
s = s.decode(detect_encoding(s), 'surrogatepass')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8c in position 5: invalid
start byte
Can someone please help me with this, thanк you in advance
any update on the Crypt::encryptString hash?
Thanks @mcfoi
it's working for me also :)