mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-13 10:16:12 +02:00
Basic support for cryptography.io
Still needs better hash function
This commit is contained in:
parent
51a6ac2d51
commit
db494597a2
3 changed files with 39 additions and 58 deletions
|
@ -1,3 +1,30 @@
|
|||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives import padding
|
||||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
||||
import hashlib
|
||||
import util
|
||||
from . import __version__
|
||||
import sys
|
||||
|
||||
def upgrade_encrypted_journal(filename, key_plain):
|
||||
"""Decrypts a journal in memory using the jrnl 1.x encryption scheme
|
||||
and returns it in plain text."""
|
||||
with open(filename) as f:
|
||||
iv_cipher = f.read()
|
||||
iv, cipher = iv_cipher[:16], iv_cipher[16:]
|
||||
decryption_key = hashlib.sha256(key_plain.encode('utf-8')).digest()
|
||||
decryptor = Cipher(algorithms.AES(decryption_key), modes.CBC(iv), default_backend())
|
||||
plain_padded = decryptor.update(cipher)
|
||||
try:
|
||||
plain_padded += decryptor.finalize()
|
||||
unpadder = padding.PKCS7(algorithms.AES.block_size).unpadder()
|
||||
plain = unpadder.update(plain_padded)
|
||||
plain += unpadder.finalize()
|
||||
except ValueError:
|
||||
return None
|
||||
return plain
|
||||
|
||||
|
||||
def upgrade_jrnl_if_necessary(config_path):
|
||||
with open(config_path) as f:
|
||||
config = f.read()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue