NEW: python script to perform encryption/decryption

This commit is contained in:
xpk 2024-03-15 07:54:40 +08:00
parent c010e2889d
commit 0c956bc418
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86
1 changed files with 35 additions and 0 deletions

35
py/pyenc.py Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/python3
# This program encrypt/decrypt files with a hard-coded password.
# Original files will be overwritten
import sys
from cryptography.fernet import Fernet
if __name__ == '__main__':
if len(sys.argv) < 3:
print('pyenc [-e|-d] files')
exit(1)
# Static password is used
f = Fernet('PjEba1U9Z5Nm8Irkqi+7+ir9j+YKVSya01aZxRUsVVI=')
if sys.argv[1] == '-e':
for infile in sys.argv[2:]:
file = open(infile, 'rb')
encrypted = f.encrypt(file.read())
file.close()
outfile = open(infile, 'wb')
outfile.write(encrypted)
outfile.close()
if sys.argv[1] == '-d':
for infile in sys.argv[2:]:
file = open(infile, 'rb')
decrypted = f.decrypt(file.read())
file.close()
outfile = open(infile, 'wb')
outfile.write(decrypted)
outfile.close()