Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Improve security
  • Loading branch information
SkyDream01 authored Feb 3, 2024
1 parent 1cd09de commit 1bd100b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
5 changes: 3 additions & 2 deletions RSA.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.backends import default_backend
import os
from ast import literal_eval
from constants import *
from config import *

Expand All @@ -26,7 +27,7 @@ def encrypt_with_public_key(message, public_key):

# 使用私钥解密消息
def decrypt_with_private_key(encrypted_message_str, private_key):
encrypted_message = eval(encrypted_message_str)
encrypted_message = literal_eval(encrypted_message_str)
key = RSA.import_key(private_key)
cipher = PKCS1_OAEP.new(key)
decrypted_message = cipher.decrypt(encrypted_message).decode()
Expand Down Expand Up @@ -57,7 +58,7 @@ def verify_signature(message, signature_bytes, public_key_bytes):
public_key_bytes,
backend=default_backend()
)
signature = eval(signature_bytes)
signature = literal_eval(signature_bytes)
try:
public_key.verify(
signature,
Expand Down
8 changes: 0 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
from utils import *


def main():
start_folder_check()
config_check()
welcome()
OptionMenu()
delete_temp_files()


if __name__ == '__main__':
main()

32 changes: 26 additions & 6 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from PIL import Image
import os
import glob
from glob import glob
from datetime import datetime
from constants import *
from RSA import *
from config import *
Expand Down Expand Up @@ -59,7 +60,14 @@ def image_encode(self):
pixel[0] = (pixel[0] & 0xFE) | int(binary_ends[index], 2) # 设置红色通道的最低位
pixels[x, y] = tuple(pixel)
index += 1
output_image_path = output_path + self.name + "_out.png"

# 获取当前时间
current_time = datetime.now()

# 格式化为指定格式
formatted_time = current_time.strftime('%y%m%d%H%M%S')

output_image_path = output_path + self.name + "_" + formatted_time + ".png"

self.image.save(output_image_path)

Expand Down Expand Up @@ -116,7 +124,7 @@ def delete_temp_files():
pattern = os.path.join(current_directory, '*.tem')

# 使用glob.glob查找匹配的文件列表
temp_files = glob.glob(pattern)
temp_files = glob(pattern)

# 循环遍历并删除每个文件
for file_path in temp_files:
Expand Down Expand Up @@ -171,7 +179,7 @@ def read_binary_message(binary_end):
def scan_img():
img_list = []
for file in os.listdir(input_path):
if file.endswith(".png") or file.endswith(".jpg") or file.endswith(".jpeg") or file.endswith(".bmp"):
if file.endswith(".png") or file.endswith(".jpg") or file.endswith(".jpeg") or file.endswith(".bmp") or file.endswith(".tif"):
img_list.append(file)
return img_list

Expand Down Expand Up @@ -216,7 +224,7 @@ def welcome():
| |_/ | (_| | (_) | |_) | | | | (_| | | | | /\__/ | | |_| | | |
\____/ \__,_|\___/|_.__/|_| |_|\__,_|_| |_| \____/|_|\__|_| |_|
Version:0.1.2
Version:0.1.5
""")

Expand Down Expand Up @@ -270,4 +278,16 @@ def OptionMenu():
public_key = load_public_key(public_key_name)
decode_img2message(private_key, public_key)
else:
print("无效的选项")
print("无效的选项")

def standing_by():
input("按下任意键结束程序...")


def main():
start_folder_check()
config_check()
welcome()
OptionMenu()
delete_temp_files()
standing_by()

0 comments on commit 1bd100b

Please sign in to comment.