Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with open('/root/Desktop/fichero.txt', 'rb') as outfile:
- datos = outfile.read()
- headers = {'Content-type': 'application/json'}
- r = requests.post("http://localhost:5000/api/encrypt", json={'file':base64.encode(datos),'alg':'aes256'}, headers=headers)
- print r.content
- from Crypto.Cipher import AES
- @app.route('/api/encrypt_file', methods=['POST'])
- def encrypt_file():
- data = request.json
- data['file'] = base64.b64decode(data['file'])
- iv = Random.new().read(16)
- cipher = AES.new(key,AES.MODE_CBC,iv)#key es byte string de 32 bits
- fichero_enc= iv + cipher.encrypt(data['file'])
- return jsonify({'file':base64.b64encode(fichero_enc)}) #aquí salta la excepción
- >> UnicodeDecodeError: 'utf8' codec can't decode byte 0x86 in position 2: invalid start byte
Add Comment
Please, Sign In to add comment