|
|
|
@ -25,6 +25,8 @@ def main():
|
|
|
|
|
|
|
|
|
|
with open(path,"rb") as f:
|
|
|
|
|
data = f.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
letter.fileName = getFileName(path)
|
|
|
|
|
letter.recvPubKey = getRecvPubKey()
|
|
|
|
|
letter.senderPubKey = getSenderPubKey()
|
|
|
|
@ -36,8 +38,7 @@ def main():
|
|
|
|
|
letter.sign = getSign(data)
|
|
|
|
|
|
|
|
|
|
print(letter.fileName)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(letter.fileBase64)
|
|
|
|
|
print(letter.sign)
|
|
|
|
|
print(letter.encryptType)
|
|
|
|
|
print(letter.encryptKey)
|
|
|
|
@ -51,9 +52,19 @@ def main():
|
|
|
|
|
return letter # 方便recv测试,以后可以删除。
|
|
|
|
|
pass
|
|
|
|
|
def selectFile() -> str:
|
|
|
|
|
s = input("输入文件路径:")
|
|
|
|
|
# s = "public.pem"
|
|
|
|
|
while True:
|
|
|
|
|
try:
|
|
|
|
|
s = input("输入文件路径:")
|
|
|
|
|
with open(s, "rb") as _:
|
|
|
|
|
pass
|
|
|
|
|
return s
|
|
|
|
|
except FileNotFoundError:
|
|
|
|
|
print("错误: 文件未找到,请输入正确的文件路径。")
|
|
|
|
|
except PermissionError:
|
|
|
|
|
print("错误: 无法访问该文件,请检查权限。")
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"发生未知错误: {e}")
|
|
|
|
|
|
|
|
|
|
# 获得文件名
|
|
|
|
|
def getFileName(fName:str) -> str:
|
|
|
|
@ -73,34 +84,35 @@ def selectSymEncryptionChoice():
|
|
|
|
|
|
|
|
|
|
# 选择加密算法
|
|
|
|
|
while True:
|
|
|
|
|
encryWay = input("Choose the way for encryption (aes/sm4): ").strip().lower() # 统一转成小写
|
|
|
|
|
encryWay = input("选择加密算法 (aes/sm4): ").strip().lower() # 统一转成小写
|
|
|
|
|
if encryWay in ["aes", "sm4"]:
|
|
|
|
|
letterWay = encryWay
|
|
|
|
|
print(f"You have selected '{encryWay}' encryption.")
|
|
|
|
|
print(f"已经选择 '{encryWay}'.")
|
|
|
|
|
break # 输入有效后退出循环
|
|
|
|
|
else:
|
|
|
|
|
print("Invalid choice. Please enter 'aes' or 'sm4'.")
|
|
|
|
|
print("非法选择,请输入 'aes' 或 'sm4'.")
|
|
|
|
|
|
|
|
|
|
# 选择加密算法的模式
|
|
|
|
|
while True:
|
|
|
|
|
if encryWay == "aes":
|
|
|
|
|
encryMode = input("Choose the encryption mode (ecb/cbc/cfb/ofb): ").strip().lower()
|
|
|
|
|
encryMode = input("选择加密算法模式 (ecb/cbc/cfb/ofb): ").strip().lower()
|
|
|
|
|
if encryMode in ["ecb", "cbc", "cfb", "ofb"]:
|
|
|
|
|
letterMode = encryMode
|
|
|
|
|
print(f"You have selected '{encryMode}' encryption mode.")
|
|
|
|
|
print(f"已选择 '{encryMode}' 加密模式.")
|
|
|
|
|
break # 输入有效后退出循环
|
|
|
|
|
else:
|
|
|
|
|
print("Invalid choice. Please enter ecb/cbc/cfb/ofb")
|
|
|
|
|
print("非法输入,请输入 ecb/cbc/cfb/ofb")
|
|
|
|
|
|
|
|
|
|
elif encryWay == "sm4":
|
|
|
|
|
encryMode = input("Choose the encryption mode (ecb/cbc): ").strip().lower()
|
|
|
|
|
encryMode = input("选择加密模式 (ecb/cbc): ").strip().lower()
|
|
|
|
|
if encryMode in ["ecb", "cbc"]:
|
|
|
|
|
letterMode = encryMode
|
|
|
|
|
print(f"You have selected '{encryMode}' encryption mode.")
|
|
|
|
|
print(f"已选择 '{encryMode}' 加密模式.")
|
|
|
|
|
break # 输入有效后退出循环
|
|
|
|
|
else:
|
|
|
|
|
print("Invalid choice. Please enter ecb/cbc")
|
|
|
|
|
print("非法输入,请输入 enter ecb/cbc")
|
|
|
|
|
|
|
|
|
|
# 返回加密方法和加密方法的模式
|
|
|
|
|
return encryWay, encryMode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -137,6 +149,7 @@ def getSign(document_bytes):
|
|
|
|
|
|
|
|
|
|
return signDocuHash
|
|
|
|
|
|
|
|
|
|
# 获得加密的方法和模式,封装信封
|
|
|
|
|
def getEncryptType():
|
|
|
|
|
encryType = f"{letterWay}_{letterMode}".upper()
|
|
|
|
|
|
|
|
|
|