-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencryption.py
42 lines (33 loc) · 1.28 KB
/
encryption.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import io
from os import stat
import h5py
import psutil
import pyAesCrypt
bufferSize = 64 * 1024
password = "some_dummy_password"
file = "/Users/bvalean/WORK/test-encryption/files/SimulationHistory.h5"
encrypted_file = file + ".aes"
if __name__ == '__main__':
print("1. {}".format(psutil.virtual_memory()))
h5_file = h5py.File(file, 'r', libver='latest')
print("2. {}".format(psutil.virtual_memory()))
print(h5_file["/"].attrs["TVB_gid"])
pyAesCrypt.encryptFile(file, encrypted_file, password, bufferSize)
fDec = io.BytesIO()
print("3. {}".format(psutil.virtual_memory()))
with open(encrypted_file, "rb") as fIn:
try:
try:
inputFileSize = stat(encrypted_file).st_size
# decrypt file stream
pyAesCrypt.decryptStream(fIn, fDec, password, bufferSize, inputFileSize)
except ValueError as exd:
raise ValueError(str(exd))
except IOError:
raise IOError("Unable to write output file.")
print("4. {}".format(psutil.virtual_memory()))
h5_file_stream = h5py.File(fDec, "r")
print("5. {}".format(psutil.virtual_memory()))
print(h5_file_stream["/"].attrs["TVB_gid"])
with open(file + "decript.h5", "wb") as fout:
fout.write(fDec.getbuffer())