1
0
Fork 0
mirror of https://github.com/HACKERALERT/Picocrypt.git synced 2024-12-29 19:02:43 +00:00

Update Picocrypt.py

This commit is contained in:
Evan Su 2021-03-21 15:56:13 -04:00 committed by GitHub
parent 86473d7656
commit 38fee8b258
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -37,13 +37,16 @@ from argon2.low_level import hash_secret_raw,Type
from Crypto.Cipher import ChaCha20_Poly1305 from Crypto.Cipher import ChaCha20_Poly1305
from Crypto.Hash import SHA3_512 as sha3_512 from Crypto.Hash import SHA3_512 as sha3_512
from secrets import compare_digest from secrets import compare_digest
from os import urandom,fsync,remove from os import urandom,fsync,remove,system
from os.path import getsize,expanduser from os.path import getsize,expanduser,dirname
from os.path import abspath
from TkinterDnD2 import *
import sys import sys
import tkinter import tkinter
import tkinter.ttk import tkinter.ttk
import tkinter.scrolledtext import tkinter.scrolledtext
import webbrowser import webbrowser
import platform
try: try:
from creedsolo import RSCodec,ReedSolomonError from creedsolo import RSCodec,ReedSolomonError
except: except:
@ -83,12 +86,17 @@ rscNotice = "Creating Reed-Solomon tables..."
unknownErrorNotice = "Unknown error occured. Please try again." unknownErrorNotice = "Unknown error occured. Please try again."
# Create root Tk # Create root Tk
tk = tkinter.Tk() tk = TkinterDnD.Tk()
tk.geometry("480x480") tk.geometry("480x480")
tk.title("Picocrypt") tk.title("Picocrypt")
tk.configure(background="#f5f6f7") tk.configure(background="#f5f6f7")
tk.resizable(0,0) tk.resizable(0,0)
def onDrop(e):
print(e)
tk.drop_target_register(DND_FILES)
tk.dnd_bind("<<Drop>>",onDrop)
# Try setting window icon if included with Picocrypt # Try setting window icon if included with Picocrypt
try: try:
favicon = tkinter.PhotoImage(file="./key.png") favicon = tkinter.PhotoImage(file="./key.png")
@ -492,9 +500,6 @@ def start():
total = getsize(inputFile) total = getsize(inputFile)
# If secure wipe enabled, create a wiper object # If secure wipe enabled, create a wiper object
if wipe:
wiper = open(inputFile,"r+b")
wiper.seek(0)
# Keep track of time because it flies... # Keep track of time because it flies...
startTime = datetime.now() startTime = datetime.now()
@ -507,11 +512,7 @@ def start():
piece = fin.read(1104905) piece = fin.read(1104905)
else: else:
piece = fin.read(chunkSize) piece = fin.read(chunkSize)
if wipe:
# If securely wipe, write random trash
# to original file after reading it
trash = urandom(len(piece))
wiper.write(trash)
# If EOF # If EOF
if not piece: if not piece:
if mode=="encrypt": if mode=="encrypt":
@ -682,6 +683,15 @@ def start():
done += 1104905 if (reedsolo and mode=="decrypt") else chunkSize done += 1104905 if (reedsolo and mode=="decrypt") else chunkSize
fout.write(data) fout.write(data)
if not kept:
fout.flush()
fsync(fout.fileno())
fout.close()
fin.close()
if wipe:
secureWipe(inputFile)
# Show appropriate notice if file corrupted or modified # Show appropriate notice if file corrupted or modified
if not kept: if not kept:
if mode=="encrypt": if mode=="encrypt":
@ -723,23 +733,13 @@ def start():
eraseBtn["state"] = "disabled" eraseBtn["state"] = "disabled"
rs.set(0) rs.set(0)
rsBtn["state"] = "disabled" rsBtn["state"] = "disabled"
if not kept:
fout.flush()
fsync(fout.fileno())
fout.close()
fin.close()
if wipe:
# Make sure to flush file
wiper.flush()
fsync(wiper.fileno())
wiper.close()
remove(inputFile)
inputFile = "" inputFile = ""
outputFile = "" outputFile = ""
password = "" password = ""
ad = "" ad = ""
kept = False kept = False
working = False working = False
# Wipe keys for safety # Wipe keys for safety
del fin,fout,cipher,key del fin,fout,cipher,key
@ -779,6 +779,15 @@ def startWorker():
thread = Thread(target=wrapper,daemon=True) thread = Thread(target=wrapper,daemon=True)
thread.start() thread.start()
def secureWipe(fin):
statusString.set("Securely erasing original file...")
if platform.system()=="Windows":
system(f'sdelete64.exe "{inputFile}" -p 4')
elif platform.system()=="Darwin":
pass
else:
system(f'shred -uz "{inputFile}"')
# ad stands for "associated data"/metadata # ad stands for "associated data"/metadata
adLabelString = tkinter.StringVar(tk) adLabelString = tkinter.StringVar(tk)
adLabelString.set(adString) adLabelString.set(adString)