-
Notifications
You must be signed in to change notification settings - Fork 2
/
decrypt.py
executable file
·51 lines (26 loc) · 971 Bytes
/
decrypt.py
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
from Crypto.PublicKey import RSA
from Crypto.Cipher import AES, PKCS1_OAEP
import sys
import requests
def decrypt():
try:
getId = sys.argv[1]
url = 'http://localhost/api/ragnrok/{}'.format(getId)
response = requests.get(url)
private_key = response.json()['private_key']
private_key = bytes(private_key, 'utf-8')
# private_key = private_key.replace(b'\\n', b'\n')
private_key = private_key.decode('unicode-escape').encode('ISO-8859-1')
enc_fernet_key = response.json()['enc_fernet_key']
enc_fernet_key = bytes(enc_fernet_key, 'utf-8')
enc_fernet_key = enc_fernet_key.decode('unicode-escape').encode('ISO-8859-1')
#Private RSA key
rsa_import = RSA.importKey(private_key)
# Private decrypter
private_crypter = PKCS1_OAEP.new(rsa_import)
# Decrypted session key
dec_fernet_key = private_crypter.decrypt(enc_fernet_key)
print(dec_fernet_key.decode('utf-8'))
except Exception as e:
print(e)
decrypt()