import os
print(os.path.join("usuario/archivos", "documento.txt"))
[204, 205]
Ejemplo fernet
# https://cryptography.io/en/latest/fernet/
from cryptography.fernet import Fernet
key = Fernet.generate_key()
# key = b'wMMR6A25Mos2L3lp0EFfl5eMR24ozQuTaVNPTgFPjbk='
print(type(key),key)
f = Fernet(key)
token = f.encrypt(b"hola mundo")
print(token)
f.decrypt(token)
Ejemplo usando AES:
import json
from base64 import b64encode
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
data = b"hola"
key = get_random_bytes(16)
print(type(key),key)
#key = b'12345678901234561234567890123456'
print(type(key),key)
cipher = AES.new(key, AES.MODE_CTR)
ct_bytes = cipher.encrypt(data)
nonce = b64encode(cipher.nonce).decode('utf-8')
ct = b64encode(ct_bytes).decode('utf-8')
result = json.dumps({'nonce':nonce, 'ciphertext':ct})
print(result)
import json
from base64 import b64decode
from Crypto.Cipher import AES
# We assume that the key was securely shared beforehand
try:
b64 = json.loads(result)
nonce = b64decode(b64['nonce'])
ct = b64decode(b64['ciphertext'])
cipher = AES.new(key, AES.MODE_CTR, nonce=nonce)
# cipher = AES.new(key, AES.MODE_CTR)
pt = cipher.decrypt(ct)
print("The message was: ", pt)
except :
print("Incorrect decryption")
l1 = [1,2,3,4]
l2 = [10,11,2]
r=map(lambda x: x+1,l1)
for x in r:
print(x)
Podemos leer un archivo en formato binario de la siguiente manera:
with open("in1.txt","rb") as archivo:
t = b''
for x in archivo.readlines():
print(x)
t += x
print(type(t),t)
Seguir los siguientes pasos
$ sudo su
$ pip3 install virtualenv
$ virtualenv -p python3 env3
$ source env3/bin/activate
[210]
$ pip install -r requirements.txt
Ejemplos podemos tener en
También te puede interesar: