-
Notifications
You must be signed in to change notification settings - Fork 0
/
cricri-csv-gpg.py
62 lines (46 loc) · 1.54 KB
/
cricri-csv-gpg.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
52
53
54
55
56
57
58
59
60
61
62
#! python3
import gnupg
import shutil
import os
import sys
import getpass
if os.path.exists('doctemp'):
shutil.rmtree('doctemp')
gpg = gnupg.GPG(homedir='doctemp')
arquivo_cri = input('Nome do arquivo criptografado: ')
x = 1
while os.path.exists(arquivo_cri) == False:
arquivo_cri = input(f'Arquivo não-encontrado.\nTente de novo ({x+1}/3):\nNome do arquivo criptografado: ')
x += 1
if x == 3:
print('Arquivo não encontrado.')
sys.exit()
arquivo_out = input('Nome do arquivo descriptografado (com a extensão .csv): ')
key = getpass.getpass('Chave privada: ')
x = 1
while os.path.exists(key) == False:
key = getpass.getpass(f'Chave não encontrada.\nTente de novo ({x+1}/3):\nNome da chave privada: ')
x += 1
if x == 3:
print('Chave não encontrada')
sys.exit()
key_data = open(key).read()
import_result = gpg.import_keys(key_data)
senha = getpass.getpass('Senha: ')
with open(arquivo_cri, 'rb') as f:
descri = gpg.decrypt_file(f, passphrase=senha, output=arquivo_out)
print('ok: ', descri.ok)
print('status: ', descri.status)
x = 1
while descri.ok == False:
senha = getpass.getpass(f'Senha errada.\nTente de novo ({x+1}/3) Senha: ')
with open(arquivo_cri, 'r') as f:
descri = gpg.decrypt_file(f, passphrase=senha)
print('ok: ', descri.ok)
print('status: ', descri.status)
x += 1
if x == 3:
print('Problema com a senha.')
sys.exit()
if os.path.exists(arquivo_out) == True:
print('\nArquivo gerado: '+os.path.realpath(arquivo_out))