Guest User

Untitled

a guest
Dec 10th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. with open('/root/Desktop/fichero.txt', 'rb') as outfile:
  2. datos = outfile.read()
  3.  
  4.  
  5. headers = {'Content-type': 'application/json'}
  6. r = requests.post("http://localhost:5000/api/encrypt", json={'file':base64.encode(datos),'alg':'aes256'}, headers=headers)
  7.  
  8. print r.content
  9.  
  10. from Crypto.Cipher import AES
  11.  
  12. @app.route('/api/encrypt_file', methods=['POST'])
  13. def encrypt_file():
  14.  
  15. data = request.json
  16.  
  17. data['file'] = base64.b64decode(data['file'])
  18.  
  19. iv = Random.new().read(16)
  20.  
  21. cipher = AES.new(key,AES.MODE_CBC,iv)#key es byte string de 32 bits
  22. fichero_enc= iv + cipher.encrypt(data['file'])
  23.  
  24. return jsonify({'file':base64.b64encode(fichero_enc)}) #aquí salta la excepción
  25.  
  26. >> UnicodeDecodeError: 'utf8' codec can't decode byte 0x86 in position 2: invalid start byte
Add Comment
Please, Sign In to add comment