update
This commit is contained in:
43
cronjob.py
43
cronjob.py
@@ -6,14 +6,13 @@
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
# import things
|
# import things
|
||||||
from cryptography.fernet import Fernet
|
|
||||||
from Crypto.Cipher import PKCS1_OAEP as RSA
|
from Crypto.Cipher import PKCS1_OAEP as RSA
|
||||||
from Crypto.Cipher import AES
|
from Crypto.Cipher import AES
|
||||||
|
from Crypto.Random import get_random_bytes
|
||||||
import os
|
import os
|
||||||
import glob
|
import glob
|
||||||
from signal import signal, SIGINT
|
from signal import signal, SIGINT
|
||||||
from goprocam import GoProCamera, constants
|
from goprocam import GoProCamera, constants
|
||||||
from base64 import b64decode, b64encode
|
|
||||||
|
|
||||||
# global vars
|
# global vars
|
||||||
location = "/home/pi/final/videos/" # location of video files, subfolders "plaintext" and "encrypted" assumed to exist
|
location = "/home/pi/final/videos/" # location of video files, subfolders "plaintext" and "encrypted" assumed to exist
|
||||||
@@ -47,21 +46,20 @@ def encryptPGP(file):
|
|||||||
key = RSA.importKey(keytext)
|
key = RSA.importKey(keytext)
|
||||||
return key.encrypt(file, 'x')[0]
|
return key.encrypt(file, 'x')[0]
|
||||||
|
|
||||||
# encrypt given (video) file and store both encrypted video and (TODO) encrypted random iv
|
# encrypt given (video) file and store both encrypted video and encrypted key
|
||||||
def encryptVideo(file):
|
def encryptVideo(file):
|
||||||
# open the file as bytes
|
# open file, generate cyrpto
|
||||||
with open(file, "rb") as og:
|
message = open(file, "rb").read()
|
||||||
message = og.read()
|
key = get_random_bytes(16)
|
||||||
# generate keys
|
print(str(key))
|
||||||
key = Fernet.generate_key()
|
cipher = AES.new(key, AES.MODE_EAX)
|
||||||
fernet = Fernet(key)
|
ciphertext, tag = cipher.encrypt_and_digest(message)
|
||||||
# encrypt file
|
# save encrypted file
|
||||||
enc = fernet.encrypt(message)
|
file_out = open(location + "encrypted/" + numFiles() + ".mpc", "wb")
|
||||||
# save the encrypted mp4
|
[ file_out.write(x) for x in (cipher.nonce, tag, ciphertext) ]
|
||||||
with open(location+"encrypted/" + numFiles() + ".mpc", "wb") as encf:
|
file_out.close()
|
||||||
encf.write(enc)
|
# save the encrypted key
|
||||||
# save the key
|
with open("keys/" + str(int(numFiles()) - 1) + ".asc", "wb+") as keyf:
|
||||||
with open("keys/" + str(int(numFiles()) - 1) + ".asc", "wb") as keyf:
|
|
||||||
keyf.write(encryptPGP(key))
|
keyf.write(encryptPGP(key))
|
||||||
|
|
||||||
# record the video and store in file location
|
# record the video and store in file location
|
||||||
@@ -70,19 +68,10 @@ takeVideo(seconds)
|
|||||||
# get all video files in folder, encrypt (get all just in case one was missed previously)
|
# get all video files in folder, encrypt (get all just in case one was missed previously)
|
||||||
fileset = [file for file in glob.glob(location + "plaintext/*.mp4", recursive=False)]
|
fileset = [file for file in glob.glob(location + "plaintext/*.mp4", recursive=False)]
|
||||||
|
|
||||||
# whether or not to print out current action
|
with open("numFiles.txt", "w+") as numf:
|
||||||
verbose = True
|
numf.write(numFiles())
|
||||||
|
|
||||||
for file in fileset:
|
for file in fileset:
|
||||||
if verbose:
|
|
||||||
print("Working on file " + file)
|
|
||||||
print("Encrypting...")
|
|
||||||
encryptVideo(file)
|
encryptVideo(file)
|
||||||
|
|
||||||
if verbose:
|
|
||||||
print("Deleting...")
|
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
|
|
||||||
if verbose:
|
|
||||||
print("Done.")
|
|
||||||
|
|
||||||
|
|||||||
1
numFiles.txt
Normal file
1
numFiles.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
3
|
||||||
Reference in New Issue
Block a user