Esempio n. 1
0
def start_encryption(email):
    dv.divide()
    tools.empty_folder('uploads')
    enc.encrypter()
    mail_id = email
    mail.send_email(mail_id)
    return render_template('success.html')
def divide():
    tools.empty_folder('files')
    tools.empty_folder('raw_data')
    FILE = tools.list_dir('uploads')
    FILE = './uploads/' + FILE[0]

    MAX = 1024 * 32  # 1	MB	-	max chapter size
    BUF = 50 * 1024 * 1024 * 1024  # 50GB	-	memory buffer size

    chapters = 0
    uglybuf = ''
    meta_data = open('raw_data/meta_data.txt', 'w')
    file__name = FILE.split('/')
    file__name = file__name[-1]
    print(file__name)
    meta_data.write("File_Name=%s\n" % (file__name))
    with open(FILE, 'rb') as src:
        while True:
            target_file = open('files/SECRET' + '%07d' % chapters, 'wb')
            written = 0
            while written < MAX:
                if len(uglybuf) > 0:
                    target_file.write(uglybuf)
                target_file.write(src.read(min(BUF, MAX - written)))
                written += min(BUF, MAX - written)
                uglybuf = src.read(1)
                if len(uglybuf) == 0:
                    break
            target_file.close()
            if len(uglybuf) == 0:
                break
            chapters += 1
    meta_data.write("chapters=%d" % (chapters + 1))
    meta_data.close()
def decrypter(Fname):
	tools.empty_folder('files')
	tools.empty_folder('./key_pem')
	list_directory = tools.list_dir('key')
	filename = './key/' + list_directory[0]
	in_f = filename
	out_f = "./key_pem/" + Fname +".pem"
	in_img = cv2.imread(in_f)
	steg = Steganography(in_img)
	key_1 = steg.decode_binary()

	secret_information = Algo1(key_1, Fname)
	list_information = secret_information.split(':::::')
	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/' + Fname + '/files'))
	for index in range(0,len(files)):
		if index%4 == 0:
			Also1_RSA(files[index],key_1_1,key_1_2, Fname)
		elif index%4 == 1:
			Also2_TrippleDES(files[index],key_2,nonce12, Fname)
		elif index%4 == 2:
			Algo3(files[index],key_3,nonce12, Fname)
		else:
			Algo4(files[index],key_4,nonce13, Fname)
Esempio n. 4
0
def restore(Fname):
	tools.empty_folder('restored_file')

	chapters = 0

	meta_data = open("./encrypted/" + Fname +'/raw_data/meta_data.txt','r')
	meta_info = []
	for row in meta_data:
		temp = row.split('\n')
		temp = temp[0]
		temp = temp.split('=')
		meta_info.append(temp[1])
	address = 'restored_file/' + meta_info[0]

	list_of_files = sorted(tools.list_dir('files'))

	with open(address,'wb') as writer:
		for file in list_of_files:
			path = 'files/' + file
			with open(path,'rb') as reader:
				for line in reader:
					writer.write(line)
				reader.close()
		writer.close()

	tools.empty_folder('files')
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)
def back_home():
    tools.empty_folder('key')
    tools.empty_folder('restored_file')
    result = engine.execute('Select * from file_contents')
    file_names = []
    keys = []
    for id in result:
        file_names.append(id[1])
    return render_template('dashboard.html',
                           name=current_user.username,
                           data=file_names)
def start_encryption(txt):
    file_data = file_contents.query.filter_by(name=txt).first()

    if file_data:
        fp = open(UPLOAD_FOLDER + txt, "wb")
        fp.write(file_data.data)
        fp.close()
        dv.divide(txt)
        tools.empty_folder('uploads')
        enc.encrypter(txt)
        return render_template('success.html', name=current_user.username)
    else:
        return render_template('exception.html', message='File not found')
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 !'
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)
            name = os.path.basename(file.filename)
            (fname, ext) = os.path.splitext(name)
            file.save(os.path.join(app.config['UPLOAD_KEY'], file.filename))

            return start_decryption(fname)
        return 'Invalid File Format !'
def encrypter(fname):
	tools.empty_folder('./encrypted/' + fname + '/files/' )
	tools.empty_folder('./key/')
	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, fname)
		elif index%4 == 1:
			Algo2(files[index],key_2,nonce12, fname)
		elif index%4 == 2:
			Algo3(files[index],key_3,nonce12, fname)
		else:
			Algo4(files[index],key_4,nonce13, fname)
	secret_information = (key_1_1)+":::::"+(key_1_2)+":::::"+(key_2)+":::::"+(key_3)+":::::"+(key_4)+":::::"+(nonce12)+":::::"+(nonce13)
	Algo1(secret_information,key_1, fname)

	# Static path to the image file for Steganography
	in_f = "./static/png.png"
	#out_f = './encrypted/' + fname + '/key/'  + fname + '.png'
	out_f = './key/'  + fname + '.png'
	in_img = cv2.imread(in_f)
	steg = Steganography(in_img)

	res = steg.encode_binary(key_1)
	cv2.imwrite(out_f, res)

	tools.empty_folder('files')
Esempio n. 11
0
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) + ":::::" + (key_1_2) + ":::::" + (
        key_2) + ":::::" + (key_3) + ":::::" + (key_4) + ":::::" + (
            nonce12) + ":::::" + (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')
Esempio n. 12
0
def back_home():
    tools.empty_folder('key')
    tools.empty_folder('restored_file')
    result = engine.execute('Select * from file_contents')
    file_names = []
    for id in result:
        file_names.append(id[1])
    if current_user.username == 'admin':
        rqst = engine.execute('SELECT name, user_Name FROM requests')
        if rqst:
            return render_template('dashboard.html',
                                   name=current_user.username,
                                   data=file_names,
                                   req=rqst)
        else:
            return render_template('dashboard.html',
                                   name=current_user.username,
                                   data=file_names)
    else:
        return render_template('user_panel.html',
                               name=current_user.username,
                               data=file_names)
Esempio n. 13
0
def divide():
    '''
	Splits uploaded binary files into chapters .000, .001,
	then on chapters we will do individually encryption.
	'''
    tools.empty_folder('files')
    tools.empty_folder('raw_data')
    FILE = tools.list_dir('uploads')
    FILE = './uploads/' + FILE[0]

    MAX = 1024 * 32  # 1	MB	-	max chapter size
    BUF = 50 * 1024 * 1024 * 1024  # 50GB	-	memory buffer size

    chapters = 0
    buf = ''
    meta_data = open('raw_data/meta_data.txt', 'w')
    file__name = FILE.split('/')
    file__name = file__name[-1]
    meta_data.write("File_Name=%s\n" % (file__name))
    with open(FILE, 'rb') as src:
        while True:
            target_file = open('files/SECRET' + '%07d' % chapters, 'wb')
            written = 0
            while written < MAX:
                if len(buf) > 0:
                    target_file.write(buf)
                target_file.write(src.read(min(BUF, MAX - written)))
                written += min(BUF, MAX - written)
                buf = src.read(1)
                if len(buf) == 0:
                    break
            target_file.close()
            if len(buf) == 0:
                break
            chapters += 1
    meta_data.write("chapters=%d" % (chapters + 1))
    meta_data.close()
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:
            file_data = file_contents.query.filter_by(
                name=file.filename).first()
            if file_data:
                return '<h1> File already Found in Database !!</h1>'
            else:
                newFile = file_contents(name=file.filename, data=file.read())
                db.session.add(newFile)
                db.session.commit()
                return '<h1> File Uploaded successfully!!</h1>'
        return 'Invalid File Format !'
def back_home():
    tools.empty_folder('key')
    tools.empty_folder('restored_file')
    return render_template('index.html')
def start_decryption():
    dec.decrypter()
    tools.empty_folder('key')
    rst.restore()
    return render_template('restore_success.html')
def start_encryption():
    dv.divide()
    tools.empty_folder('uploads')
    enc.encrypter()
    return render_template('success.html')