-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathaes.py
More file actions
executable file
·73 lines (68 loc) · 2.61 KB
/
aes.py
File metadata and controls
executable file
·73 lines (68 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# ParanoiDF. A combination of several PDF analysis/manipulation tools to
# produce one of the most technically useful PDF analysis tools.
#
# Idea proposed by Julio Hernandez-Castro, University of Kent, UK.
# By Patrick Wragg
# University of Kent
# 21/07/2014
#
# With thanks to:
# Julio Hernandez-Castro, my supervisor.
# Jose Miguel Esparza for writing PeePDF (the basis of this tool).
# Didier Stevens for his "make-PDF" tools.
# Blake Hartstein for Jsunpack-n.
# Yusuke Shinyama for Pdf2txt.py (PDFMiner)
# Nacho Barrientos Arias for Pdfcrack.
# Kovid Goyal for Calibre (DRM removal).
# Jay Berkenbilt for QPDF.
#
# Copyright (C) 2014-2018 Patrick Wragg
#
# This file is part of ParanoiDF.
#
# ParanoiDF is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ParanoiDF is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ParanoiDF. If not, see <http://www.gnu.org/licenses/>.
#
"""
Created from the demonstration of the pythonaes package.
Copyright (c) 2010, Adam Newman http://www.caller9.com/
Licensed under the MIT license http://www.opensource.org/licenses/mit-license.php
"""
import sys
from aespython import key_expander, aes_cipher, cbc_mode
def decryptData(data, password = None, keyLength = None, mode = 'CBC'):
'''
Method added for peepdf
'''
decryptedData = ''
if keyLength == None:
keyLength = len(password)*8
if keyLength not in [128, 192, 256]:
return (-1, 'Bad length key in AES decryption process')
iv = map(ord, data[:16])
key = map(ord, password)
data = data[16:]
if len(data) % 16 != 0:
data = data[:-(len(data)%16)]
keyExpander = key_expander.KeyExpander(keyLength)
expandedKey = keyExpander.expand(key)
aesCipher = aes_cipher.AESCipher(expandedKey)
if mode == 'CBC':
aesMode = cbc_mode.CBCMode(aesCipher, 16)
aesMode.set_iv(iv)
for i in range(0,len(data),16):
ciphertext = map(ord,data[i:i+16])
decryptedBytes = aesMode.decrypt_block(ciphertext)
for byte in decryptedBytes:
decryptedData += chr(byte)
return (0, decryptedData)