Add AES encryption util
This commit is contained in:
parent
65c68cb6d0
commit
98cc175810
38
client/fstream-util-aes_to_pipe.py
Executable file
38
client/fstream-util-aes_to_pipe.py
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import sys
|
||||||
|
|
||||||
|
oldexcepthook = sys.excepthook
|
||||||
|
def newexcepthook(type,value,traceback):
|
||||||
|
oldexcepthook(type,value,traceback)
|
||||||
|
#input("Press ENTER to quit.")
|
||||||
|
sys.excepthook = newexcepthook
|
||||||
|
|
||||||
|
import os
|
||||||
|
p = os.path.join
|
||||||
|
pUp = os.path.dirname
|
||||||
|
s = False
|
||||||
|
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
|
||||||
|
s = os.path.realpath(sys.executable)
|
||||||
|
else:
|
||||||
|
s = os.path.realpath(__file__)
|
||||||
|
sp = pUp(s)
|
||||||
|
|
||||||
|
# script start
|
||||||
|
try:
|
||||||
|
from Cryptodome.Cipher import AES
|
||||||
|
except:
|
||||||
|
from Crypto.Cipher import AES
|
||||||
|
import hashlib
|
||||||
|
bufferSize = 128
|
||||||
|
unbufferedStdout = os.fdopen(sys.stdout.fileno(),"wb",0) # Make unbuffered stdout
|
||||||
|
|
||||||
|
salt = b'\x85a`8\xa1n \xb6\x9aRU/\x0e\xdc*\xa3'
|
||||||
|
pw = hashlib.pbkdf2_hmac("sha256",os.environ["fstream_aespass"].encode("utf-8"), salt, 100000, 32)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
iv = sys.stdin.buffer.read(AES.block_size)
|
||||||
|
if len(iv) != AES.block_size: sys.exit(0)
|
||||||
|
data = sys.stdin.buffer.read(bufferSize)
|
||||||
|
if len(data) != bufferSize: sys.exit(0)
|
||||||
|
cipher = AES.new(pw, AES.MODE_CBC, iv = iv)
|
||||||
|
unbufferedStdout.write(cipher.decrypt(data))
|
37
client/fstream-util-pipe_to_aes.py
Executable file
37
client/fstream-util-pipe_to_aes.py
Executable file
@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import sys
|
||||||
|
|
||||||
|
oldexcepthook = sys.excepthook
|
||||||
|
def newexcepthook(type,value,traceback):
|
||||||
|
oldexcepthook(type,value,traceback)
|
||||||
|
#input("Press ENTER to quit.")
|
||||||
|
sys.excepthook = newexcepthook
|
||||||
|
|
||||||
|
import os
|
||||||
|
p = os.path.join
|
||||||
|
pUp = os.path.dirname
|
||||||
|
s = False
|
||||||
|
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
|
||||||
|
s = os.path.realpath(sys.executable)
|
||||||
|
else:
|
||||||
|
s = os.path.realpath(__file__)
|
||||||
|
sp = pUp(s)
|
||||||
|
|
||||||
|
# script start
|
||||||
|
try:
|
||||||
|
from Cryptodome.Cipher import AES
|
||||||
|
except:
|
||||||
|
from Crypto.Cipher import AES
|
||||||
|
import hashlib
|
||||||
|
bufferSize = 128
|
||||||
|
unbufferedStdout = os.fdopen(sys.stdout.fileno(),"wb",0) # Make unbuffered stdout
|
||||||
|
|
||||||
|
salt = b'\x85a`8\xa1n \xb6\x9aRU/\x0e\xdc*\xa3'
|
||||||
|
pw = hashlib.pbkdf2_hmac("sha256",os.environ["fstream_aespass"].encode("utf-8"), salt, 100000, 32)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
data = sys.stdin.buffer.read(bufferSize)
|
||||||
|
if len(data) != bufferSize: sys.exit(0)
|
||||||
|
cipher = AES.new(pw, AES.MODE_CBC)
|
||||||
|
unbufferedStdout.write(cipher.iv)
|
||||||
|
unbufferedStdout.write(cipher.encrypt(data))
|
Loading…
Reference in New Issue
Block a user