taolib.testing.oauth.crypto.token_encryption#

Token 加密模块。

使用 Fernet 对称加密安全存储 OAuth Token。

Classes#

TokenEncryptor

Token 加密器。

Functions#

generate_encryption_key(→ str)

生成新的 Fernet 加密密钥。

Module Contents#

taolib.testing.oauth.crypto.token_encryption.generate_encryption_key() str#

生成新的 Fernet 加密密钥。

返回:

Base64 编码的 32 字节密钥字符串

class taolib.testing.oauth.crypto.token_encryption.TokenEncryptor(encryption_key: str)#

Token 加密器。

使用 Fernet 对称加密对 OAuth Token 进行加密和解密。

参数:

encryption_key -- Fernet 兼容的加密密钥(Base64 编码的 32 字节)

_fernet#
encrypt(plaintext: str) str#

加密明文。

参数:

plaintext -- 要加密的明文字符串

返回:

Base64 编码的密文字符串

decrypt(ciphertext: str) str#

解密密文。

参数:

ciphertext -- Base64 编码的密文字符串

返回:

解密后的明文字符串

抛出:

OAuthTokenDecryptionError -- 解密失败

static rotate_key(old_key: str, new_key: str, ciphertext: str) str#

密钥轮换:用旧密钥解密后用新密钥重新加密。

参数:
  • old_key -- 旧的加密密钥

  • new_key -- 新的加密密钥

  • ciphertext -- 用旧密钥加密的密文

返回:

用新密钥加密的密文

抛出:

OAuthTokenDecryptionError -- 用旧密钥解密失败