Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to resolve this error coming after uploading file on browser #4

Open
kartiksinghprajapati opened this issue May 5, 2020 · 9 comments

Comments

@kartiksinghprajapati
Copy link

TypeError
TypeError: can only concatenate str (not "bytes") to str

Traceback (most recent call last)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2463, in call

def __call__(self, environ, start_response):
    """The WSGI server calls the Flask application object as the
    WSGI application. This calls :meth:`wsgi_app` which can be
    wrapped to applying middleware."""
    return self.wsgi_app(environ, start_response)

def __repr__(self):
    return "<%s %r>" % (self.__class__.__name__, self.name)

File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask_compat.py", line 39, in reraise
raise value
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask_compat.py", line 39, in reraise
raise value
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1935, in dispatch_request
return self.view_functionsrule.endpoint
File "C:\Users\HP\Desktop\Secure-File-Storage-Using-Hybrid-Cryptography-master\app.py", line 86, in upload_file
return start_encryption()
File "C:\Users\HP\Desktop\Secure-File-Storage-Using-Hybrid-Cryptography-master\app.py", line 27, in start_encryption
enc.encrypter()
File "C:\Users\HP\Desktop\Secure-File-Storage-Using-Hybrid-Cryptography-master\encrypter.py", line 88, in encrypter
Algo1_extented(files[index],key_1_1,key_1_2)
File "C:\Users\HP\Desktop\Secure-File-Storage-Using-Hybrid-Cryptography-master\encrypter.py", line 23, in Algo1_extented
raw = raw + line
TypeError: can only concatenate str (not "bytes") to str
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.

You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:

dump() shows all variables in the frame
dump(obj) dumps all that's known about the object

@imSunnyk
Copy link

imSunnyk commented May 7, 2020

TypeError
TypeError: can only concatenate str (not "bytes") to str

Traceback (most recent call last)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2463, in call

def __call__(self, environ, start_response):
    """The WSGI server calls the Flask application object as the
    WSGI application. This calls :meth:`wsgi_app` which can be
    wrapped to applying middleware."""
    return self.wsgi_app(environ, start_response)

def __repr__(self):
    return "<%s %r>" % (self.__class__.__name__, self.name)

File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask_compat.py", line 39, in reraise
raise value
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask_compat.py", line 39, in reraise
raise value
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1935, in dispatch_request
return self.view_functionsrule.endpoint
File "C:\Users\HP\Desktop\Secure-File-Storage-Using-Hybrid-Cryptography-master\app.py", line 86, in upload_file
return start_encryption()
File "C:\Users\HP\Desktop\Secure-File-Storage-Using-Hybrid-Cryptography-master\app.py", line 27, in start_encryption
enc.encrypter()
File "C:\Users\HP\Desktop\Secure-File-Storage-Using-Hybrid-Cryptography-master\encrypter.py", line 88, in encrypter
Algo1_extented(files[index],key_1_1,key_1_2)
File "C:\Users\HP\Desktop\Secure-File-Storage-Using-Hybrid-Cryptography-master\encrypter.py", line 23, in Algo1_extented
raw = raw + line
TypeError: can only concatenate str (not "bytes") to str
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.

You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:

dump() shows all variables in the frame
dump(obj) dumps all that's known about the object

Are you running this in newer version of python....if yes....then run in python 2.7.15...I was having same issue with newer ones

@mohitdhawan92
Copy link

please help me out for this problem as shown in previous people comments
provide steps for instillation of the softwares for making perfect project

@mohitdhawan92
Copy link

TypeError
TypeError: can only concatenate str (not "bytes") to str

Traceback (most recent call last)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2463, in call

def call(self, environ, start_response):
"""The WSGI server calls the Flask application object as the
WSGI application. This calls :meth:wsgi_app which can be
wrapped to applying middleware."""
return self.wsgi_app(environ, start_response)

def repr(self):
return "<%s %r>" % (self.class.name, self.name)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask_compat.py", line 39, in reraise
raise value
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask_compat.py", line 39, in reraise
raise value
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1935, in dispatch_request
return self.view_functionsrule.endpoint
File "C:\Users\HP\Desktop\Secure-File-Storage-Using-Hybrid-Cryptography-master\app.py", line 86, in upload_file
return start_encryption()
File "C:\Users\HP\Desktop\Secure-File-Storage-Using-Hybrid-Cryptography-master\app.py", line 27, in start_encryption
enc.encrypter()
File "C:\Users\HP\Desktop\Secure-File-Storage-Using-Hybrid-Cryptography-master\encrypter.py", line 88, in encrypter
Algo1_extented(files[index],key_1_1,key_1_2)
File "C:\Users\HP\Desktop\Secure-File-Storage-Using-Hybrid-Cryptography-master\encrypter.py", line 23, in Algo1_extented
raw = raw + line
TypeError: can only concatenate str (not "bytes") to str
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.

You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:

dump() shows all variables in the frame
dump(obj) dumps all that's known about the object

this problem occurred at the time of app.py file running.please provide steps to solve this problem ,and you have any software in your google drive then send it by link

@asif4011
Copy link

Convert all the Strings concatinating to bytes into bytes. I will upload the code which will run on Python3
app.py

import os
from flask import Flask, request, redirect, url_for, render_template, send_from_directory, send_file , flash
from werkzeug.utils import secure_filename
import tools
import divider as dv
import encrypter as enc
import decrypter as dec
import restore as rst

UPLOAD_FOLDER = './uploads/'
UPLOAD_KEY = './key/'
ALLOWED_EXTENSIONS = set(['pem'])

app = Flask(name)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['UPLOAD_KEY'] = UPLOAD_KEY

#port = int(os.getenv('PORT', 8000))

def allowed_file(filename):
return '.' in filename and
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS

def start_encryption():
dv.divide()
tools.empty_folder('uploads')
enc.encrypter()
return render_template('success.html')

def start_decryption():
dec.decrypter()
tools.empty_folder('key')
rst.restore()
return render_template('restore_success.html')

@app.route('/return-key/My_Key.pem')
def return_key():
list_directory = tools.list_dir('key')
filename = './key/' + list_directory[0]
return send_file(filename, attachment_filename='My_Key.pem')

@app.route('/return-file/')
def return_file():
list_directory = tools.list_dir('restored_file')
filename = './restored_file/' + list_directory[0]
print ("")
print (list_directory[0])
print ("
")
return send_file(filename, attachment_filename=list_directory[0], as_attachment=True)

@app.route('/download/')
def downloads():
return render_template('download.html')

@app.route('/upload')
def call_page_upload():
return render_template('upload.html')

@app.route('/home')
def back_home():
tools.empty_folder('key')
tools.empty_folder('restored_file')
return render_template('index.html')

@app.route('/')
def index():
return render_template('index.html')

@app.route('/data', methods=['GET', 'POST'])
def upload_file():
tools.empty_folder('uploads')
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
flash('No selected file')
return 'NO FILE SELECTED'
if file:
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename))
return start_encryption()
return 'Invalid File Format !'

@app.route('/download_data', methods=['GET', 'POST'])
def upload_key():
tools.empty_folder('key')
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
flash('No selected file')
return 'NO FILE SELECTED'
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_KEY'], file.filename))
return start_decryption()
return 'Invalid File Format !'

if name == 'main':
app.run(host='127.0.0.1', port=8000, debug=True)
#app.run()

encrypter.py

import tools
import os
from cryptography.fernet import Fernet, MultiFernet
from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
from cryptography.hazmat.primitives.ciphers.aead import AESCCM

def Algo1(data, key):
f = Fernet(key)
target_file = open("raw_data/store_in_me.enc","wb")
secret_data = f.encrypt(data)
target_file.write(secret_data)
target_file.close()

def Algo1_extented(filename, key1, key2):
f = MultiFernet([Fernet(key1),Fernet(key2)])
source_filename = 'files/' + filename
target_filename = 'encrypted/' + filename
file = open(source_filename,'rb')
target_file = open(target_filename,'wb')
raw = b""
for line in file:
raw = raw + line
secret_data = f.encrypt(raw)
target_file.write(secret_data)
file.close()
target_file.close()

def Algo2(filename, key, nonce):
aad = "authenticated but unencrypted data"
chacha = ChaCha20Poly1305(key)
source_filename = 'files/' + filename
target_filename = 'encrypted/' + filename
file = open(source_filename,'rb')
target_file = open(target_filename,'wb')
raw = b""
for line in file:
raw = raw + line
secret_data = chacha.encrypt(nonce, raw, aad)
target_file.write(secret_data)
file.close()
target_file.close()

def Algo3(filename, key, nonce):
aad = "authenticated but unencrypted data"
aesgcm = AESGCM(key)
source_filename = 'files/' + filename
target_filename = 'encrypted/' + filename
file = open(source_filename,'rb')
target_file = open(target_filename,'wb')
raw = b""
for line in file:
raw = raw + line
secret_data = aesgcm.encrypt(nonce, raw, aad)
target_file.write(secret_data)
file.close()
target_file.close()

def Algo4(filename, key, nonce):
aad = "authenticated but unencrypted data"
aesccm = AESCCM(key)
source_filename = 'files/' + filename
target_filename = 'encrypted/' + filename
file = open(source_filename,'rb')
target_file = open(target_filename,'wb')
raw = b""
for line in file:
raw = raw + line
secret_data = aesccm.encrypt(nonce, raw, aad)
target_file.write(secret_data)
file.close()
target_file.close()

def encrypter():
tools.empty_folder('key')
tools.empty_folder('encrypted')
key_1 = Fernet.generate_key()
key_1_1 = Fernet.generate_key()
key_1_2 = Fernet.generate_key()
key_2 = ChaCha20Poly1305.generate_key()
key_3 = AESGCM.generate_key(bit_length=128)
key_4 = AESCCM.generate_key(bit_length=128)
nonce13 = os.urandom(13)
nonce12 = os.urandom(12)
files = sorted(tools.list_dir('files'))
for index in range(0,len(files)):
if index%4 == 0:
Algo1_extented(files[index],key_1_1,key_1_2)
elif index%4 == 1:
Algo2(files[index],key_2,nonce12)
elif index%4 == 2:
Algo3(files[index],key_3,nonce12)
else:
Algo4(files[index],key_4,nonce13)
secret_information = (key_1_1)+b":::::"+(key_1_2)+b":::::"+(key_2)+b":::::"+(key_3)+b":::::"+(key_4)+b":::::"+(nonce12)+b":::::"+(nonce13)
Algo1(secret_information,key_1)
public_key = open("./key/Taale_Ki_Chabhi.pem","wb")
public_key.write(key_1)
public_key.close()
tools.empty_folder('files')

decrypter.py

import tools
from cryptography.fernet import Fernet, MultiFernet
from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
from cryptography.hazmat.primitives.ciphers.aead import AESCCM

def Algo1(key):
f = Fernet(key)
target_file = open("raw_data/store_in_me.enc","rb")
secret_data = b""
for line in target_file:
secret_data = secret_data + line
data = f.decrypt(secret_data)
target_file.close()
return data

def Algo1_extented(filename, key1, key2):
f = MultiFernet([Fernet(key1),Fernet(key2)])
source_filename = 'encrypted/' + filename
target_filename = 'files/' + filename
file = open(source_filename,'rb')
target_file = open(target_filename,'wb')
raw = b""
for line in file:
raw = raw + line
secret_data = f.decrypt(line)
target_file.write(secret_data)
file.close()
target_file.close()

def Algo2(filename, key, nonce):
aad = "authenticated but unencrypted data"
chacha = ChaCha20Poly1305(key)
source_filename = 'encrypted/' + filename
target_filename = 'files/' + filename
file = open(source_filename,'rb')
target_file = open(target_filename,'wb')
raw = b""
for line in file:
raw = raw + line
secret_data = chacha.decrypt(nonce, raw, aad)
target_file.write(secret_data)
file.close()
target_file.close()

def Algo3(filename, key, nonce):
aad = "authenticated but unencrypted data"
aesgcm = AESGCM(key)
source_filename = 'encrypted/' + filename
target_filename = 'files/' + filename
file = open(source_filename,'rb')
target_file = open(target_filename,'wb')
raw = b""
for line in file:
raw = raw + line
secret_data = aesgcm.decrypt(nonce, raw, aad)
target_file.write(secret_data)
file.close()
target_file.close()

def Algo4(filename, key, nonce):
aad = "authenticated but unencrypted data"
aesccm = AESCCM(key)
source_filename = 'encrypted/' + filename
target_filename = 'files/' + filename
file = open(source_filename,'rb')
target_file = open(target_filename,'wb')
raw = b""
for line in file:
raw = raw + line
secret_data = aesccm.decrypt(nonce, raw, aad)
target_file.write(secret_data)
file.close()
target_file.close()

def decrypter():
tools.empty_folder('files')
key_1 = b""
list_directory = tools.list_dir('key')
filename = './key/' + list_directory[0]
public_key = open(filename,"rb")
for line in public_key:
key_1 = key_1 + line
public_key.close()
secret_information = Algo1(key_1)
list_information = secret_information.split(b':::::')
key_1_1 = list_information[0]
key_1_2 = list_information[1]
key_2 = list_information[2]
key_3 = list_information[3]
key_4 = list_information[4]
nonce12 = list_information[5]
nonce13 = list_information[6]
files = sorted(tools.list_dir('encrypted'))
for index in range(0,len(files)):
if index%4 == 0:
Algo1_extented(files[index],key_1_1,key_1_2)
elif index%4 == 1:
Algo2(files[index],key_2,nonce12)
elif index%4 == 2:
Algo3(files[index],key_3,nonce12)
else:
Algo4(files[index],key_4,nonce13)

@kartiksinghprajapati
Copy link
Author

kartiksinghprajapati commented Feb 25, 2021 via email

@Hemanthob
Copy link

Convert all the Strings concatinating to bytes into bytes. I will upload the code which will run on Python3 app.py

import os from flask import Flask, request, redirect, url_for, render_template, send_from_directory, send_file , flash from werkzeug.utils import secure_filename import tools import divider as dv import encrypter as enc import decrypter as dec import restore as rst

UPLOAD_FOLDER = './uploads/' UPLOAD_KEY = './key/' ALLOWED_EXTENSIONS = set(['pem'])

app = Flask(name) app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER app.config['UPLOAD_KEY'] = UPLOAD_KEY

#port = int(os.getenv('PORT', 8000))

def allowed_file(filename): return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS

def start_encryption(): dv.divide() tools.empty_folder('uploads') enc.encrypter() return render_template('success.html')

def start_decryption(): dec.decrypter() tools.empty_folder('key') rst.restore() return render_template('restore_success.html')

@app.route('/return-key/My_Key.pem') def return_key(): list_directory = tools.list_dir('key') filename = './key/' + list_directory[0] return send_file(filename, attachment_filename='My_Key.pem')

@app.route('/return-file/') def return_file(): list_directory = tools.list_dir('restored_file') filename = './restored_file/' + list_directory[0] print ("") print (list_directory[0]) print ("") return send_file(filename, attachment_filename=list_directory[0], as_attachment=True)

@app.route('/download/') def downloads(): return render_template('download.html')

@app.route('/upload') def call_page_upload(): return render_template('upload.html')

@app.route('/home') def back_home(): tools.empty_folder('key') tools.empty_folder('restored_file') return render_template('index.html')

@app.route('/') def index(): return render_template('index.html')

@app.route('/data', methods=['GET', 'POST']) def upload_file(): tools.empty_folder('uploads') if request.method == 'POST': # check if the post request has the file part if 'file' not in request.files: flash('No file part') return redirect(request.url) file = request.files['file'] # if user does not select file, browser also # submit a empty part without filename if file.filename == '': flash('No selected file') return 'NO FILE SELECTED' if file: filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename)) return start_encryption() return 'Invalid File Format !'

@app.route('/download_data', methods=['GET', 'POST']) def upload_key(): tools.empty_folder('key') if request.method == 'POST': # check if the post request has the file part if 'file' not in request.files: flash('No file part') return redirect(request.url) file = request.files['file'] # if user does not select file, browser also # submit a empty part without filename if file.filename == '': flash('No selected file') return 'NO FILE SELECTED' if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_KEY'], file.filename)) return start_decryption() return 'Invalid File Format !'

if name == 'main': app.run(host='127.0.0.1', port=8000, debug=True) #app.run()

encrypter.py

import tools import os from cryptography.fernet import Fernet, MultiFernet from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305 from cryptography.hazmat.primitives.ciphers.aead import AESGCM from cryptography.hazmat.primitives.ciphers.aead import AESCCM

def Algo1(data, key): f = Fernet(key) target_file = open("raw_data/store_in_me.enc","wb") secret_data = f.encrypt(data) target_file.write(secret_data) target_file.close()

def Algo1_extented(filename, key1, key2): f = MultiFernet([Fernet(key1),Fernet(key2)]) source_filename = 'files/' + filename target_filename = 'encrypted/' + filename file = open(source_filename,'rb') target_file = open(target_filename,'wb') raw = b"" for line in file: raw = raw + line secret_data = f.encrypt(raw) target_file.write(secret_data) file.close() target_file.close()

def Algo2(filename, key, nonce): aad = "authenticated but unencrypted data" chacha = ChaCha20Poly1305(key) source_filename = 'files/' + filename target_filename = 'encrypted/' + filename file = open(source_filename,'rb') target_file = open(target_filename,'wb') raw = b"" for line in file: raw = raw + line secret_data = chacha.encrypt(nonce, raw, aad) target_file.write(secret_data) file.close() target_file.close()

def Algo3(filename, key, nonce): aad = "authenticated but unencrypted data" aesgcm = AESGCM(key) source_filename = 'files/' + filename target_filename = 'encrypted/' + filename file = open(source_filename,'rb') target_file = open(target_filename,'wb') raw = b"" for line in file: raw = raw + line secret_data = aesgcm.encrypt(nonce, raw, aad) target_file.write(secret_data) file.close() target_file.close()

def Algo4(filename, key, nonce): aad = "authenticated but unencrypted data" aesccm = AESCCM(key) source_filename = 'files/' + filename target_filename = 'encrypted/' + filename file = open(source_filename,'rb') target_file = open(target_filename,'wb') raw = b"" for line in file: raw = raw + line secret_data = aesccm.encrypt(nonce, raw, aad) target_file.write(secret_data) file.close() target_file.close()

def encrypter(): tools.empty_folder('key') tools.empty_folder('encrypted') key_1 = Fernet.generate_key() key_1_1 = Fernet.generate_key() key_1_2 = Fernet.generate_key() key_2 = ChaCha20Poly1305.generate_key() key_3 = AESGCM.generate_key(bit_length=128) key_4 = AESCCM.generate_key(bit_length=128) nonce13 = os.urandom(13) nonce12 = os.urandom(12) files = sorted(tools.list_dir('files')) for index in range(0,len(files)): if index%4 == 0: Algo1_extented(files[index],key_1_1,key_1_2) elif index%4 == 1: Algo2(files[index],key_2,nonce12) elif index%4 == 2: Algo3(files[index],key_3,nonce12) else: Algo4(files[index],key_4,nonce13) secret_information = (key_1_1)+b":::::"+(key_1_2)+b":::::"+(key_2)+b":::::"+(key_3)+b":::::"+(key_4)+b":::::"+(nonce12)+b":::::"+(nonce13) Algo1(secret_information,key_1) public_key = open("./key/Taale_Ki_Chabhi.pem","wb") public_key.write(key_1) public_key.close() tools.empty_folder('files')

decrypter.py

import tools from cryptography.fernet import Fernet, MultiFernet from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305 from cryptography.hazmat.primitives.ciphers.aead import AESGCM from cryptography.hazmat.primitives.ciphers.aead import AESCCM

def Algo1(key): f = Fernet(key) target_file = open("raw_data/store_in_me.enc","rb") secret_data = b"" for line in target_file: secret_data = secret_data + line data = f.decrypt(secret_data) target_file.close() return data

def Algo1_extented(filename, key1, key2): f = MultiFernet([Fernet(key1),Fernet(key2)]) source_filename = 'encrypted/' + filename target_filename = 'files/' + filename file = open(source_filename,'rb') target_file = open(target_filename,'wb') raw = b"" for line in file: raw = raw + line secret_data = f.decrypt(line) target_file.write(secret_data) file.close() target_file.close()

def Algo2(filename, key, nonce): aad = "authenticated but unencrypted data" chacha = ChaCha20Poly1305(key) source_filename = 'encrypted/' + filename target_filename = 'files/' + filename file = open(source_filename,'rb') target_file = open(target_filename,'wb') raw = b"" for line in file: raw = raw + line secret_data = chacha.decrypt(nonce, raw, aad) target_file.write(secret_data) file.close() target_file.close()

def Algo3(filename, key, nonce): aad = "authenticated but unencrypted data" aesgcm = AESGCM(key) source_filename = 'encrypted/' + filename target_filename = 'files/' + filename file = open(source_filename,'rb') target_file = open(target_filename,'wb') raw = b"" for line in file: raw = raw + line secret_data = aesgcm.decrypt(nonce, raw, aad) target_file.write(secret_data) file.close() target_file.close()

def Algo4(filename, key, nonce): aad = "authenticated but unencrypted data" aesccm = AESCCM(key) source_filename = 'encrypted/' + filename target_filename = 'files/' + filename file = open(source_filename,'rb') target_file = open(target_filename,'wb') raw = b"" for line in file: raw = raw + line secret_data = aesccm.decrypt(nonce, raw, aad) target_file.write(secret_data) file.close() target_file.close()

def decrypter(): tools.empty_folder('files') key_1 = b"" list_directory = tools.list_dir('key') filename = './key/' + list_directory[0] public_key = open(filename,"rb") for line in public_key: key_1 = key_1 + line public_key.close() secret_information = Algo1(key_1) list_information = secret_information.split(b':::::') key_1_1 = list_information[0] key_1_2 = list_information[1] key_2 = list_information[2] key_3 = list_information[3] key_4 = list_information[4] nonce12 = list_information[5] nonce13 = list_information[6] files = sorted(tools.list_dir('encrypted')) for index in range(0,len(files)): if index%4 == 0: Algo1_extented(files[index],key_1_1,key_1_2) elif index%4 == 1: Algo2(files[index],key_2,nonce12) elif index%4 == 2: Algo3(files[index],key_3,nonce12) else: Algo4(files[index],key_4,nonce13)

Man, I am Hemanth, can I get ur whatsapp number, I need little help

@shivang8
Copy link
Owner

shivang8 commented Oct 6, 2021 via email

@Hemanthob
Copy link

Hey Hemant, Sorry for the trouble... The code is broken since the cryptography library got updated. You may refer to the report for the details on the last known good code and libraries.

On Wed, Oct 6, 2021 at 11:32 AM Hemanthob @.*> wrote: Convert all the Strings concatinating to bytes into bytes. I will upload the code which will run on Python3 app.py import os from flask import Flask, request, redirect, url_for, render_template, send_from_directory, send_file , flash from werkzeug.utils import secure_filename import tools import divider as dv import encrypter as enc import decrypter as dec import restore as rst UPLOAD_FOLDER = './uploads/' UPLOAD_KEY = './key/' ALLOWED_EXTENSIONS = set(['pem']) app = Flask(name) app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER app.config['UPLOAD_KEY'] = UPLOAD_KEY #port = int(os.getenv('PORT', 8000)) def allowed_file(filename): return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS def start_encryption(): dv.divide() tools.empty_folder('uploads') enc.encrypter() return render_template('success.html') def start_decryption(): dec.decrypter() tools.empty_folder('key') rst.restore() return render_template('restore_success.html') @app.route('/return-key/My_Key.pem') def return_key(): list_directory = tools.list_dir('key') filename = './key/' + list_directory[0] return send_file(filename, attachment_filename='My_Key.pem') @app.route('/return-file/') def return_file(): list_directory = tools.list_dir('restored_file') filename = './restored_file/' + list_directory[0] print ("") print (list_directory[0]) print ("") return send_file(filename, attachment_filename=list_directory[0], as_attachment=True) @app.route('/download/') def downloads(): return render_template('download.html') @app.route('/upload') def call_page_upload(): return render_template('upload.html') @app.route('/home') def back_home(): tools.empty_folder('key') tools.empty_folder('restored_file') return render_template('index.html') @app.route('/') def index(): return render_template('index.html') @app.route('/data', methods=['GET', 'POST']) def upload_file(): tools.empty_folder('uploads') if request.method == 'POST': # check if the post request has the file part if 'file' not in request.files: flash('No file part') return redirect(request.url) file = request.files['file'] # if user does not select file, browser also # submit a empty part without filename if file.filename == '': flash('No selected file') return 'NO FILE SELECTED' if file: filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename)) return start_encryption() return 'Invalid File Format !' @app.route('/download_data', methods=['GET', 'POST']) def upload_key(): tools.empty_folder('key') if request.method == 'POST': # check if the post request has the file part if 'file' not in request.files: flash('No file part') return redirect(request.url) file = request.files['file'] # if user does not select file, browser also # submit a empty part without filename if file.filename == '': flash('No selected file') return 'NO FILE SELECTED' if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_KEY'], file.filename)) return start_decryption() return 'Invalid File Format !' if name == 'main': app.run(host='127.0.0.1', port=8000, debug=True) #app.run() encrypter.py import tools import os from cryptography.fernet import Fernet, MultiFernet from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305 from cryptography.hazmat.primitives.ciphers.aead import AESGCM from cryptography.hazmat.primitives.ciphers.aead import AESCCM def Algo1(data, key): f = Fernet(key) target_file = open("raw_data/store_in_me.enc","wb") secret_data = f.encrypt(data) target_file.write(secret_data) target_file.close() def Algo1_extented(filename, key1, key2): f = MultiFernet([Fernet(key1),Fernet(key2)]) source_filename = 'files/' + filename target_filename = 'encrypted/' + filename file = open(source_filename,'rb') target_file = open(target_filename,'wb') raw = b"" for line in file: raw = raw + line secret_data = f.encrypt(raw) target_file.write(secret_data) file.close() target_file.close() def Algo2(filename, key, nonce): aad = "authenticated but unencrypted data" chacha = ChaCha20Poly1305(key) source_filename = 'files/' + filename target_filename = 'encrypted/' + filename file = open(source_filename,'rb') target_file = open(target_filename,'wb') raw = b"" for line in file: raw = raw + line secret_data = chacha.encrypt(nonce, raw, aad) target_file.write(secret_data) file.close() target_file.close() def Algo3(filename, key, nonce): aad = "authenticated but unencrypted data" aesgcm = AESGCM(key) source_filename = 'files/' + filename target_filename = 'encrypted/' + filename file = open(source_filename,'rb') target_file = open(target_filename,'wb') raw = b"" for line in file: raw = raw + line secret_data = aesgcm.encrypt(nonce, raw, aad) target_file.write(secret_data) file.close() target_file.close() def Algo4(filename, key, nonce): aad = "authenticated but unencrypted data" aesccm = AESCCM(key) source_filename = 'files/' + filename target_filename = 'encrypted/' + filename file = open(source_filename,'rb') target_file = open(target_filename,'wb') raw = b"" for line in file: raw = raw + line secret_data = aesccm.encrypt(nonce, raw, aad) target_file.write(secret_data) file.close() target_file.close() def encrypter(): tools.empty_folder('key') tools.empty_folder('encrypted') key_1 = Fernet.generate_key() key_1_1 = Fernet.generate_key() key_1_2 = Fernet.generate_key() key_2 = ChaCha20Poly1305.generate_key() key_3 = AESGCM.generate_key(bit_length=128) key_4 = AESCCM.generate_key(bit_length=128) nonce13 = os.urandom(13) nonce12 = os.urandom(12) files = sorted(tools.list_dir('files')) for index in range(0,len(files)): if index%4 == 0: Algo1_extented(files[index],key_1_1,key_1_2) elif index%4 == 1: Algo2(files[index],key_2,nonce12) elif index%4 == 2: Algo3(files[index],key_3,nonce12) else: Algo4(files[index],key_4,nonce13) secret_information = (key_1_1)+b":::::"+(key_1_2)+b":::::"+(key_2)+b":::::"+(key_3)+b":::::"+(key_4)+b":::::"+(nonce12)+b":::::"+(nonce13) Algo1(secret_information,key_1) public_key = open("./key/Taale_Ki_Chabhi.pem","wb") public_key.write(key_1) public_key.close() tools.empty_folder('files') decrypter.py import tools from cryptography.fernet import Fernet, MultiFernet from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305 from cryptography.hazmat.primitives.ciphers.aead import AESGCM from cryptography.hazmat.primitives.ciphers.aead import AESCCM def Algo1(key): f = Fernet(key) target_file = open("raw_data/store_in_me.enc","rb") secret_data = b"" for line in target_file: secret_data = secret_data + line data = f.decrypt(secret_data) target_file.close() return data def Algo1_extented(filename, key1, key2): f = MultiFernet([Fernet(key1),Fernet(key2)]) source_filename = 'encrypted/' + filename target_filename = 'files/' + filename file = open(source_filename,'rb') target_file = open(target_filename,'wb') raw = b"" for line in file: raw = raw + line secret_data = f.decrypt(line) target_file.write(secret_data) file.close() target_file.close() def Algo2(filename, key, nonce): aad = "authenticated but unencrypted data" chacha = ChaCha20Poly1305(key) source_filename = 'encrypted/' + filename target_filename = 'files/' + filename file = open(source_filename,'rb') target_file = open(target_filename,'wb') raw = b"" for line in file: raw = raw + line secret_data = chacha.decrypt(nonce, raw, aad) target_file.write(secret_data) file.close() target_file.close() def Algo3(filename, key, nonce): aad = "authenticated but unencrypted data" aesgcm = AESGCM(key) source_filename = 'encrypted/' + filename target_filename = 'files/' + filename file = open(source_filename,'rb') target_file = open(target_filename,'wb') raw = b"" for line in file: raw = raw + line secret_data = aesgcm.decrypt(nonce, raw, aad) target_file.write(secret_data) file.close() target_file.close() def Algo4(filename, key, nonce): aad = "authenticated but unencrypted data" aesccm = AESCCM(key) source_filename = 'encrypted/' + filename target_filename = 'files/' + filename file = open(source_filename,'rb') target_file = open(target_filename,'wb') raw = b"" for line in file: raw = raw + line secret_data = aesccm.decrypt(nonce, raw, aad) target_file.write(secret_data) file.close() target_file.close() def decrypter(): tools.empty_folder('files') key_1 = b"" list_directory = tools.list_dir('key') filename = './key/' + list_directory[0] public_key = open(filename,"rb") for line in public_key: key_1 = key_1 + line public_key.close() secret_information = Algo1(key_1) list_information = secret_information.split(b':::::') key_1_1 = list_information[0] key_1_2 = list_information[1] key_2 = list_information[2] key_3 = list_information[3] key_4 = list_information[4] nonce12 = list_information[5] nonce13 = list_information[6] files = sorted(tools.list_dir('encrypted')) for index in range(0,len(files)): if index%4 == 0: Algo1_extented(files[index],key_1_1,key_1_2) elif index%4 == 1: Algo2(files[index],key_2,nonce12) elif index%4 == 2: Algo3(files[index],key_3,nonce12) else: Algo4(files[index],key_4,nonce13) Man, I am Hemanth, can I get ur whatsapp number, I need little help — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#4 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC7W3J2JLURSIRBUWWGMPWLUFPRAJANCNFSM4MZOVONA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

can i get ur number please?
or this is my number 7032312387 text me

@MohamedMinkaz
Copy link

TypeError TypeError: can only concatenate str (not "bytes") to str

Traceback (most recent call last) File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2463, in call

def __call__(self, environ, start_response):
    """The WSGI server calls the Flask application object as the
    WSGI application. This calls :meth:`wsgi_app` which can be
    wrapped to applying middleware."""
    return self.wsgi_app(environ, start_response)

def __repr__(self):
    return "<%s %r>" % (self.__class__.__name__, self.name)

File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2449, in wsgi_app response = self.handle_exception(e) File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1866, in handle_exception reraise(exc_type, exc_value, tb) File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask_compat.py", line 39, in reraise raise value File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2446, in wsgi_app response = self.full_dispatch_request() File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1951, in full_dispatch_request rv = self.handle_user_exception(e) File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1820, in handle_user_exception reraise(exc_type, exc_value, tb) File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask_compat.py", line 39, in reraise raise value File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1949, in full_dispatch_request rv = self.dispatch_request() File "C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1935, in dispatch_request return self.view_functionsrule.endpoint File "C:\Users\HP\Desktop\Secure-File-Storage-Using-Hybrid-Cryptography-master\app.py", line 86, in upload_file return start_encryption() File "C:\Users\HP\Desktop\Secure-File-Storage-Using-Hybrid-Cryptography-master\app.py", line 27, in start_encryption enc.encrypter() File "C:\Users\HP\Desktop\Secure-File-Storage-Using-Hybrid-Cryptography-master\encrypter.py", line 88, in encrypter Algo1_extented(files[index],key_1_1,key_1_2) File "C:\Users\HP\Desktop\Secure-File-Storage-Using-Hybrid-Cryptography-master\encrypter.py", line 23, in Algo1_extented raw = raw + line TypeError: can only concatenate str (not "bytes") to str The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error. To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.

You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:

dump() shows all variables in the frame dump(obj) dumps all that's known about the object

import tools
import os
from cryptography.fernet import Fernet, MultiFernet
from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
from cryptography.hazmat.primitives.ciphers.aead import AESCCM

def Algo1(data, key):
f = Fernet(key)
target_file = open("raw_data/store_in_me.enc","wb")
secret_data = f.encrypt(data)
target_file.write(secret_data)
target_file.close()

def Algo1_extented(filename, key1, key2):
f = MultiFernet([Fernet(key1),Fernet(key2)])
source_filename = 'files/' + filename
target_filename = 'encrypted/' + filename
file = open(source_filename,'rb')
target_file = open(target_filename,'wb')
raw = b""
for line in file:
raw = raw+line
secret_data = f.encrypt(raw)
target_file.write(secret_data)
file.close()
target_file.close()

def Algo2(filename, key, nonce):
aad = "authenticated but unencrypted data"
chacha = ChaCha20Poly1305(key)
source_filename = 'files/' + filename
target_filename = 'encrypted/' + filename
file = open(source_filename,'rb')
target_file = open(target_filename,'wb')
raw = b""
for line in file:
raw = raw + line
secret_data = chacha.encrypt(nonce, raw, aad)
target_file.write(secret_data)
file.close()
target_file.close()

def Algo3(filename, key, nonce):
aad = "authenticated but unencrypted data"
aesgcm = AESGCM(key)
source_filename = 'files/' + filename
target_filename = 'encrypted/' + filename
file = open(source_filename,'rb')
target_file = open(target_filename,'wb')
raw = b""
for line in file:
raw = raw + line
secret_data = aesgcm.encrypt(nonce, raw, aad)
target_file.write(secret_data)
file.close()
target_file.close()

def Algo4(filename, key, nonce):
aad = "authenticated but unencrypted data"
aesccm = AESCCM(key)
source_filename = 'files/' + filename
target_filename = 'encrypted/' + filename
file = open(source_filename,'rb')
target_file = open(target_filename,'wb')
raw = b""
for line in file:
raw = raw + line
secret_data = aesccm.encrypt(nonce, raw, aad)
target_file.write(secret_data)
file.close()
target_file.close()

def encrypter():
tools.empty_folder('key')
tools.empty_folder('encrypted')
key_1 = Fernet.generate_key()
key_1_1 = Fernet.generate_key()
key_1_2 = Fernet.generate_key()
key_2 = ChaCha20Poly1305.generate_key()
key_3 = AESGCM.generate_key(bit_length=128)
key_4 = AESCCM.generate_key(bit_length=128)
nonce13 = os.urandom(13)
nonce12 = os.urandom(12)
files = sorted(tools.list_dir('files'))
for index in range(0,len(files)):
if index%4 == 0:
Algo1_extented(files[index],key_1_1,key_1_2)
elif index%4 == 1:
Algo2(files[index],key_2,nonce12)
elif index%4 == 2:
Algo3(files[index],key_3,nonce12)
else:
Algo4(files[index],key_4,nonce13)
secret_information = (key_1_1)+b":::::"+(key_1_2)+b":::::"+(key_2)+b":::::"+(key_3)+b":::::"+(key_4)+b":::::"+(nonce12)+b":::::"+(nonce13)
Algo1(secret_information,key_1)
public_key = open("./key/Taale_Ki_Chabhi.pem","wb")
public_key.write(key_1)
public_key.close()
tools.empty_folder('files')

replace this file for encryption

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants