decoding from base64 in a portable way

Python2
Rémi Vanicat 2020-05-08 17:51:40 +02:00
rodzic 3166273622
commit 2fbf2c1c5f
1 zmienionych plików z 5 dodań i 2 usunięć

Wyświetl plik

@ -63,6 +63,7 @@ import zipfile
from zipfile import ZipInfo, ZipFile, ZIP_STORED, ZIP_DEFLATED
from contextlib import closing
import xml.etree.ElementTree as etree
import base64
# Wrap a stream so that output gets flushed immediately
# and also make sure that any unicode strings get
@ -421,9 +422,11 @@ def decryptBook(userkey, inpath, outpath):
if len(bookkey) != 172:
print(u"{0:s} is not a secure Adobe Adept ePub.".format(os.path.basename(inpath)))
return 1
bookkey = rsa.decrypt(bookkey.decode('base64'))
bookkey = bookkey.encode('ascii')
bookkey = base64.b64decode(bookkey)
bookkey = rsa.decrypt(bookkey)
# Padded as per RSAES-PKCS1-v1_5
if bookkey[-17] != '\x00':
if bookkey[-17] != '\x00' and bookkey[-17] != 0:
print(u"Could not decrypt {0:s}. Wrong key".format(os.path.basename(inpath)))
return 2
encryption = inf.read('META-INF/encryption.xml')