-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdecrypt.py
More file actions
executable file
·31 lines (24 loc) · 849 Bytes
/
decrypt.py
File metadata and controls
executable file
·31 lines (24 loc) · 849 Bytes
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
#!/usr/bin/env python
import sys, os
from Crypto.PublicKey import RSA
from Crypto.Cipher import AES
from Crypto import Random
if len(sys.argv) != 2:
print('Usage: {} <LOG_FILE>'.format(sys.argv[0]))
exit(1)
key_file = os.environ.get('PRIVATE_KEY', 'keys/key')
log_file = sys.argv[1]
with open(key_file, 'r') as f:
private_key = RSA.importKey(f.read())
with open(log_file, 'r') as f:
log = f.read()
with open('{}_aes'.format(log_file), 'rb') as f:
encrypted_aes_key = f.read()
# decrypt the AES key with the private key
decrypted_aes_key = private_key.decrypt(encrypted_aes_key)
# parse the initialization vector and use it
# along with decrypted AES key to decrypt the log
iv = log[0:AES.block_size]
aes_cipher = AES.new(decrypted_aes_key, AES.MODE_CFB, iv)
decrypted_log = aes_cipher.decrypt(log[AES.block_size:])
print(decrypted_log)