From 768f9e870ac0ef780c4fee5496fa8457c1a84cfd Mon Sep 17 00:00:00 2001 From: mason Date: Tue, 15 Mar 2022 12:24:26 +0800 Subject: [PATCH] updaate aesIv for 1.2.2-dev --- typora.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/typora.py b/typora.py index a26a865..53d52a2 100644 --- a/typora.py +++ b/typora.py @@ -29,6 +29,7 @@ else: log.add(sys.stderr, level="INFO") AES_KEY = struct.pack("<4Q", *[0x252A4C7BD0B85281, 0xA31BD92CE099F719, 0x13E283392646D82D, 0x118BDE501CF74120]) +AES_IV = struct.pack("<4L", *[0x33706964, 0x5387CDD2, 0xD05F336D, 0x53F82468]) def _mkDir(_path): @@ -43,10 +44,10 @@ def _mkDir(_path): def decScript(b64: bytes, prettify: bool): lCode = b64decode(b64) - # iv: the first 16 bytes of the file - aesIv = lCode[0:16] + # iv + aesIv = AES_IV # cipher text - cipherText = lCode[16:] + cipherText = lCode[:] # AES 256 CBC ins = AES.new(key=AES_KEY, iv=aesIv, mode=AES.MODE_CBC) code = unpad(ins.decrypt(cipherText), 16, 'pkcs7') @@ -106,10 +107,10 @@ def extractWdec(asarPath, path, prettify): def encScript(_code: bytes, compress): if compress: _code = jsmin(_code.decode(), quote_chars="'\"`").encode() - aesIv = urandom(16) + aesIv = AES_IV cipherText = _code ins = AES.new(key=AES_KEY, iv=aesIv, mode=AES.MODE_CBC) - enc = aesIv + ins.encrypt(pad(cipherText, 16, 'pkcs7')) + enc = ins.encrypt(pad(cipherText, 16, 'pkcs7')) lCode = b64encode(enc) return lCode