Skip to content

Commit

Permalink
beta release
Browse files Browse the repository at this point in the history
  • Loading branch information
DRVR1 committed Feb 12, 2023
1 parent fd991cf commit 3b125d7
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 62 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ todo.txt
FileCrypt-log.txt
__pycache__/funcs.cpython-310.pyc
res/__pycache__/config.cpython-310.pyc
__pycache__/nuitka.cpython-310.pyc
main.build/module.PIL.BlpImagePlugin.const
*.const
*.c
Binary file added bin/FileCrypt BETA.exe
Binary file not shown.
171 changes: 134 additions & 37 deletions funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@
from tkinter.filedialog import askopenfilenames
from tkinter.filedialog import asksaveasfilename


#import wx.lib.agw.multidirdialog as MDD
import random
import tkfilebrowser
import pathlib
import wx
import os
import customtkinter
import sys
from tkinter.messagebox import showinfo
import pathlib
import fast_file_encryption as ffe
from res import config
import pyAesCrypt

#check if the program was frozen with pyinstaller/nuitka
Expand Down Expand Up @@ -51,6 +48,8 @@ def write(self,input):
self.lineNumber += 1
self.textbox.insert(tkinter.INSERT,str(self.lineNumber)+'. ' + input + '\n')
self.textbox.configure(state='disabled')
self.textbox.see("end")
self.textbox.update()
def save(self):
file = asksaveasfilename(title='Select where to save your file',defaultextension='.txt',initialfile='FileCrypt-log')
if file:
Expand Down Expand Up @@ -85,6 +84,7 @@ def __init__(self, writer_main_window:Writer,writer_Encrypt_Decrypt_Window:Write

#user selected files - dir
self.targets = []
self.errors = []

#objects
self.writer_main_window = writer_main_window
Expand All @@ -103,7 +103,7 @@ def safedelete(self,path, passes=1): #secure delete feature, credits to kindall
delfile.write(os.urandom(length))
os.remove(path)

def savekeys(self): #enter password and zip
def savekeys(self,passw=False): #enter password and zip
showinfo('Information','An explorer window will popup, please select the directory where the keys folder will be created.')
path = askdirectory(title='Select the folder where the keys folder will be saved',mustexist=True)

Expand All @@ -127,7 +127,7 @@ def savekeys(self): #enter password and zip

ffe.save_key_pair(public_key=self.public_path,private_key=self.private_path)
self.writer_main_window.write('Keys generated')
if(self.password):
if(passw):
self.writer_main_window.write('Encrypting private key with loaded password')
try:
self.encrypt_Private()
Expand All @@ -141,8 +141,23 @@ def savekeys(self): #enter password and zip
else:
self.writer_main_window.write('Operation canceled.')

def printPaths(self): #prints selected files and dirs in the selected textbox
def encrypt_Private(self):
#encrypt source
if not self.private_path:
print('private key path not set, cant encrypt private.')
return
if not self.password:
print('error, not password given to decrypt private key.')
return
self.private_encrypted_path = pathlib.Path(os.path.join(self.folder_path,self.name_private_encrypted))
pyAesCrypt.encryptFile(self.private_path, self.private_encrypted_path, self.password)
self.safedelete(self.private_path,3)#safe delete source (decrypted private key)

def printPaths(self): #prints user selected files in the textbox
self.writer_Encrypt_Decrypt_Window.clear()
if not self.targets:
writer_Encrypt_Decrypt_Window.write('No files selected')
return
lenght = len(self.targets)
if lenght > 3000:
self.writer_Encrypt_Decrypt_Window.write(str(lenght) + ' files selected')
Expand All @@ -152,17 +167,16 @@ def printPaths(self): #prints selected files and dirs in the selected textbox
pass

def select_folders(self):
a = wx.App(0)

dirs = tkfilebrowser.askopendirnames(None,title='Select folder/s')
for folder in dirs:
for path, dirs, files in os.walk(folder):
for file in files:
if file.endswith('.lnk'):
continue
fullpath = os.path.join(path,file)
if fullpath not in self.targets:
self.targets.append(fullpath)
#dirs = tkfilebrowser.askopendirnames(None,title='Select folder/s')
dir = askdirectory(title='Select folder')
#for folder in dirs:
for path, dirs, files in os.walk(dir):
for file in files:
if file.endswith('.lnk'):
continue
fullpath = os.path.join(path,file)
if fullpath not in self.targets:
self.targets.append(fullpath)
self.printPaths()
pass

Expand All @@ -180,57 +194,140 @@ def clearTargets(self):
self.writer_Encrypt_Decrypt_Window.clear()
self.writer_Encrypt_Decrypt_Window.write('No files selected')
def encrypt_files(self):
self.errors = []
excluded = False
errordeleting = False
errorEncrypting = False
if not self.publicKey:
writer_Encrypt_Decrypt_Window.write('No public key loaded. Please select your public key.')
self.loadpublic()
writer_Encrypt_Decrypt_Window.clear()
return
if not self.targets:
self.writer_Encrypt_Decrypt_Window.clear()
self.writer_Encrypt_Decrypt_Window.write('No files/folder selected')
return
self.writer_Encrypt_Decrypt_Window.clear()
for target in self.targets:
if target.endswith('.ffe'):
writer_Encrypt_Decrypt_Window.write('excluding ' + target + ' was already encrypted.')
excluded = True
continue
encryptor = ffe.Encryptor(self.publicKey)
try:
destiny = target + '.ffe'
target = pathlib.Path(target)
destiny = pathlib.Path(destiny)
self.writer_Encrypt_Decrypt_Window.write('Encrypting ' + str(target))
encryptor.copy_encrypted(target,destiny)
self.writer_Encrypt_Decrypt_Window.write('encrypted ' + str(target))
self.writer_Encrypt_Decrypt_Window.write('Encrypted ' + str(target))
except:
writer_Encrypt_Decrypt_Window.write('error encrypting ' + str(target))
errorEncrypting = True
errormsj = 'Error encrypting ' + str(target)
writer_Encrypt_Decrypt_Window.write(errormsj)
self.errors.append(errormsj)
continue
try:
self.safedelete(target)
except:
writer_Encrypt_Decrypt_Window.write('Error deleting unencrypted ' + str(target))
showinfo('Error deleting unencrypted file','An error ocurred while trying to delete an unencrypted file, please close any programs that may be opening this file. ' + str(target))
errordeleting = True
errormsj = 'Error deleting unencrypted ' + str(target)
writer_Encrypt_Decrypt_Window.write(errormsj)
self.errors.append(errormsj)
os.remove(destiny)
return
pass
if excluded:
showinfo('File/s were excluded','Looks like some files were already encrypted and have been exluded from the encryption.')
if errordeleting:
showinfo('Error deleting unencrypted file/s','An error ocurred while trying to delete an unencrypted file/s, please look at the log and delete those files, for safety. ')
if errorEncrypting:
showinfo('Error encrypting file/s','An error ocurred while trying to encrypt a file. Maybe permisions are needed, or the file was already encrypted. Please check the log ')
if excluded or errordeleting or errorEncrypting:
self.writer_Encrypt_Decrypt_Window.clear()
for error in self.errors:
self.writer_Encrypt_Decrypt_Window.write(error)

def decrypt_files(self,extframe,app,wind,window_passwordInput):

def encrypt_Private(self):
if self.public_path:
res = askquestion
pass
#encrypt source
if not self.private_path:
print('private key path not set, cant encrypt private.')
if not self.privateKey:
self.writer_Encrypt_Decrypt_Window.write('No private key loaded, please select your private key.')
self.loadprivate(extframe,app,wind,window_passwordInput)
return

if not self.targets:
self.writer_Encrypt_Decrypt_Window.write('No files/folder selected')
return
self.private_encrypted_path = pathlib.Path(os.path.join(self.folder_path,self.name_private_encrypted))
pyAesCrypt.encryptFile(self.private_path, self.private_encrypted_path, self.password)
#safe delete source (decrypted private key)
self.safedelete(self.private_path,3)
decryptor = ffe.Decryptor(self.privateKey)

self.decrypt_errors = []

for file in self.targets:
if not file.endswith('.ffe'):
writer_Encrypt_Decrypt_Window.write('excluding ' + file + ' was not encrypted or does not exist.')
continue

destiny = file[:-4] #removes .ffe extension
try:
writer_Encrypt_Decrypt_Window.write('Decrypting ' + file + '.')
decryptor.copy_decrypted(pathlib.Path(file),pathlib.Path(destiny))
writer_Encrypt_Decrypt_Window.write('Decrypted ' + file + '.')
except:
error = 'Error decrypting file ' + str(file) + ' check if other program opened the file.'
writer_Encrypt_Decrypt_Window.write(error)
self.decrypt_errors.append(error)
continue
try:
os.remove(file)
except:
error = 'Error deleting encrypted file ' + file + ' But was decrypted sucessfully.'
writer_Encrypt_Decrypt_Window.write(error)
self.decrypt_errors.append(error)

if self.decrypt_errors:
self.writer_Encrypt_Decrypt_Window.clear()
showinfo('Errors, check the log','There were errors when decrypting file/s. Please check the log.')
for error in self.decrypt_errors:
self.writer_Encrypt_Decrypt_Window.write(error)

def loadpublic(self): #enter password and unzip
showinfo('Information','An explorer window will popup, please select your public key')
self.public_path = askopenfilename(title='Select your public key') # show an "Open" dialog box and return the path to the selected file
self.publicKey=ffe.read_public_key(pathlib.Path(self.public_path))
print('public object '+ str(self.publicKey))
self.writer_Encrypt_Decrypt_Window.write('Public key loaded from ' + self.public_path)

def decryptPrivate(self): #after getting the password, decrypt private key
try:
home = os.path.expanduser('~')
tempf = os.path.join(home,str(random.randint(99,999999999)))
pyAesCrypt.decryptFile(self.private_encrypted_path,tempf,self.password) #writes decrypted private key to RAM
self.privateKey = ffe.read_private_key(pathlib.Path(tempf))
self.safedelete(tempf)
self.writer_Encrypt_Decrypt_Window.write('Private key loaded from ' + self.private_encrypted_path)
except:
self.writer_Encrypt_Decrypt_Window.write('Error decrypting private key, check your password!')


def loadprivate(self,extframe,app,wind,window_passwordInput):
showinfo('Information','An explorer window will popup, please select your private key')
self.private_path = askopenfilename(title='Select your private key') # show an "Open" dialog box and return the path to the selected file
try:
self.privateKey=ffe.read_private_key(pathlib.Path(self.private_path))
self.writer_Encrypt_Decrypt_Window.write('Private key loaded from ' + self.private_path)
except:
writer_Encrypt_Decrypt_Window.write('Error loading private key. It may be encrypted, or wrong path.')
self.private_encrypted_path = self.private_path
self.private_path = ''
res = askquestion('Password','Are you trying to open an encrypted private key?')
if res=='yes':
window_passwordInput(app,extframe,loadingprivate=True) #decrypt after password input
return
else:
return

def unload_keys(self):
self.publicKey = ''
self.privateKey = ''
self.public_path = ''
self.private_path = ''
self.writer_Encrypt_Decrypt_Window.write('Keys were unloaded.')
#objects
writer_main_window = Writer() # a writer for the main window
writer_Encrypt_Decrypt_Window = Writer() # a writer for the encrypt_decrypt window
Expand Down
Loading

0 comments on commit 3b125d7

Please sign in to comment.