-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncrypt
More file actions
23 lines (18 loc) · 666 Bytes
/
Encrypt
File metadata and controls
23 lines (18 loc) · 666 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
### Encriptamos con GPG ####
### Encriptamos con GPG ####
import gnupg
from google.colab import files
# Inicializa el objeto GPG
gpg = gnupg.GPG()
# Pide al usuario el archivo a cifrar
file = files.upload()
filename = list(file.keys())[0]
# Pide al usuario la contraseña para cifrar
password = input("Introduzca la contraseña para cifrar: ")
# Cifra el archivo con GPG
with open(filename, 'rb') as f:
encrypted_data = gpg.encrypt(f.read(), symmetric='AES256', passphrase=password)
with open(filename + ".gpg", "wb") as outfile:
outfile.write(str(encrypted_data).encode('utf-8'))
# Descarga el archivo cifrado
files.download(filename + ".gpg")