mirror of
https://github.com/apprenticeharper/DeDRM_tools
synced 2025-01-13 20:01:14 +01:00
decoding from base64 in a portable way
This commit is contained in:
parent
3166273622
commit
2fbf2c1c5f
1 changed files with 5 additions and 2 deletions
|
@ -63,6 +63,7 @@ import zipfile
|
||||||
from zipfile import ZipInfo, ZipFile, ZIP_STORED, ZIP_DEFLATED
|
from zipfile import ZipInfo, ZipFile, ZIP_STORED, ZIP_DEFLATED
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
import xml.etree.ElementTree as etree
|
import xml.etree.ElementTree as etree
|
||||||
|
import base64
|
||||||
|
|
||||||
# Wrap a stream so that output gets flushed immediately
|
# Wrap a stream so that output gets flushed immediately
|
||||||
# and also make sure that any unicode strings get
|
# and also make sure that any unicode strings get
|
||||||
|
@ -421,9 +422,11 @@ def decryptBook(userkey, inpath, outpath):
|
||||||
if len(bookkey) != 172:
|
if len(bookkey) != 172:
|
||||||
print(u"{0:s} is not a secure Adobe Adept ePub.".format(os.path.basename(inpath)))
|
print(u"{0:s} is not a secure Adobe Adept ePub.".format(os.path.basename(inpath)))
|
||||||
return 1
|
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
|
# 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)))
|
print(u"Could not decrypt {0:s}. Wrong key".format(os.path.basename(inpath)))
|
||||||
return 2
|
return 2
|
||||||
encryption = inf.read('META-INF/encryption.xml')
|
encryption = inf.read('META-INF/encryption.xml')
|
||||||
|
|
Loading…
Reference in a new issue