模块 encryption
encryption 模块提供了一组用于数据保护和安全通信的高级函数。它简化了使用密码派生密钥加密和解密字符串的过程,并为 S/MIME 电子邮件验证和解密提供专门的处理,以确保邮件的完整性和机密性。
TIPCommon.encryption.decrypt
TIPCommon.encryption.decrypt(enc_data: bytes, key: str) → str
使用提供的密码解密数据。
参数
| 参数 | |
|---|---|
enc_data |
bytes要解密的加密数据。 |
key |
str在解密过程中用于密钥生成的密码。 |
返回值
解密后的消息。
返回类型
str
TIPCommon.encryption.decrypt_email
TIPCommon.encryption.decrypt_email(smime_email_config: SmimeEmailConfig, logger: ScriptLogger) → Message
检查电子邮件是否经过加密或签名,并执行必要的解密或验证。
参数
| 参数 | |
|---|---|
smime_email_config |
SmimeEmailConfig
一个配置对象,包含电子邮件消息 ( |
logger |
ScriptLogger
一个用于记录解密和验证过程的 |
返回值
包含解密或验证内容的 message 对象。
返回类型
email.message.Message
TIPCommon.encryption.encrypt
TIPCommon.encryption.encrypt(data: str, key: str) → bytes
使用提供的密钥加密 JSON 字符串。
参数
| 参数 | |
|---|---|
data |
str
要加密的 JSON 字符串。 |
key |
str
加密过程中用于生成密钥的密码。 |
返回值
加密后的消息(以字节串形式表示)。
返回类型
bytes
TIPCommon.encryption.get_private_key
TIPCommon.encryption.get_private_key(password: str) → bytes
根据提供的密码派生加密密钥。
参数
| 参数 | |
|---|---|
password |
str
生成私钥所用的密码字符串。 |
返回值
表示派生私钥的字节字符串。
返回类型
bytes