You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.9 KiB
65 lines
1.9 KiB
# 模式,文件,自己的公钥从哪里来,别人的公钥从哪里来
|
|
from entity.Letter import Letter
|
|
from tool.symmetric.AES import AESUtils
|
|
|
|
|
|
def main():
|
|
# 用户输入各种数据填充letter字段
|
|
# 获取用户的公私钥对进行签名
|
|
# 使用对方的公钥进行加密
|
|
# 发送信件
|
|
pass
|
|
|
|
|
|
def sendLetter(letter: Letter, target="192.168.195.162:8426"):
|
|
# 向目标ip和端口发送指定的信件
|
|
pass
|
|
|
|
# 选择对称加密的方法和模式(aes/sm2)
|
|
def selectSymEncryptionChoice():
|
|
encryWay = ""
|
|
encryMode = ""
|
|
|
|
# 选择加密算法
|
|
while True:
|
|
encryWay = input("Choose the way for encryption (aes/sm2): ").strip().lower() # 统一转成小写
|
|
if encryWay in ["aes", "sm2"]:
|
|
print(f"You have selected '{encryWay}' encryption.")
|
|
break # 输入有效后退出循环
|
|
else:
|
|
print("Invalid choice. Please enter 'aes' or 'sm2'.")
|
|
|
|
# 选择加密算法的模式
|
|
while True:
|
|
if encryWay == "aes":
|
|
encryMode = input("Choose the encryption mode (ecb/cbc/cfb/ofb): ").strip().lower()
|
|
if encryMode in ["ecb", "cbc", "cfb", "ofb"]:
|
|
print(f"You have selected '{encryMode}' encryption mode.")
|
|
break # 输入有效后退出循环
|
|
else:
|
|
print("Invalid choice. Please enter ecb/cbc/cfb/ofb")
|
|
|
|
elif encryWay == "sm2":
|
|
print()
|
|
break # 输入有效后退出循环
|
|
|
|
return encryWay, encryMode
|
|
|
|
|
|
# 使用对称加密,返回加密后的数据和随机生成的密钥
|
|
def SymEncryption():
|
|
|
|
# 获得加密的方法和加密的模式
|
|
way, mode = selectSymEncryptionChoice()
|
|
|
|
if way == "aes":
|
|
aesUtils = AESUtils()
|
|
encryptedData, key = aesUtils.encrypt("test", mode=mode) # 这里data要改为文件内容
|
|
return encryptedData
|
|
|
|
if way == "sm2":
|
|
pass
|
|
|
|
def getKey():
|
|
pass
|