Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python script to decrypt file encrypted by Monaca
# Blogpost:
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives import padding
from cryptography.hazmat.backends import default_backend
from base64 import b64decode, b64encode
import argparse
def encrypt(key, iv, data):
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
encryptor = cipher.encryptor()
encrypted = encryptor.update(data) + encryptor.finalize()
return encrypted
def decrypt(key, iv, data):
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
decryptor = cipher.decryptor()
plain = decryptor.update(data) + decryptor.finalize()
return plain
def parsekey(hash):
key = bytes.fromhex(hash)
iv = [ord(s) for s in hash[0:16]]
return key, bytes(iv)
def isEncrypted(data):
header = [24, 8, 77, 69, 1, 13, 10, 0]
def main():
parser = argparse.ArgumentParser(description="Decrypt file encrypted by MonacaEncrypt Plugin")
parser.add_argument("-k", "--key", help="Key Hash", action="store", default=False, required=True)
parser.add_argument("-f", "--file", help="File to decrypt", action="store", default=False, required=True)
args = parser.parse_args()
key,iv = parsekey(args.key)
with open(args.file, 'rb') as f:
data =
print(decrypt(key, iv, data[8:]).decode("utf-8", 'backslashreplace'))
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment