Skip to content

Instantly share code, notes, and snippets.

@asauber
Created July 15, 2016 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asauber/b86e538dc2886d2c7a03c4b97c30048d to your computer and use it in GitHub Desktop.
Save asauber/b86e538dc2886d2c7a03c4b97c30048d to your computer and use it in GitHub Desktop.
Decrypt a jrnl journal
#!/usr/bin/env python3
from Crypto.Cipher import AES
import hashlib
import sys
import argparse
import getpass
parser = argparse.ArgumentParser()
parser.add_argument("filepath", help="journal file to decrypt")
args = parser.parse_args()
pwd = getpass.getpass()
key = hashlib.sha256(pwd.encode('utf-8')).digest()
with open(args.filepath, 'rb') as f:
ciphertext = f.read()
crypto = AES.new(key, AES.MODE_CBC, ciphertext[:16])
plain = crypto.decrypt(ciphertext[16:])
plain = plain.strip(plain[-1:])
plain = plain.decode("utf-8")
print(plain)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment