1、增加调用 AI 视频生成能力和虚拟素材库管理的对外api
2、增加后台apikkey管理 3、增加apikey单独的模型定价 4、增加apikey调用情况 5、完善所有数据的注释增加
This commit is contained in:
@@ -40,6 +40,27 @@ def decrypt_temp_token(token: str) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
def encrypt_text(plaintext: str) -> str:
|
||||
"""使用 AES-256-GCM 加密字符串,返回 base64 编码的密文。"""
|
||||
import os
|
||||
aesgcm = AESGCM(get_aes_key())
|
||||
nonce = os.urandom(12) # 96-bit nonce for GCM
|
||||
ciphertext = aesgcm.encrypt(nonce, plaintext.encode(), None)
|
||||
return base64.urlsafe_b64encode(nonce + ciphertext).decode()
|
||||
|
||||
|
||||
def decrypt_text(token: str) -> str | None:
|
||||
"""解密 AES-256-GCM 加密的字符串。失败返回 None。"""
|
||||
try:
|
||||
token_bytes = base64.urlsafe_b64decode(token)
|
||||
nonce = token_bytes[:12]
|
||||
ciphertext = token_bytes[12:]
|
||||
aesgcm = AESGCM(get_aes_key())
|
||||
return aesgcm.decrypt(nonce, ciphertext, None).decode()
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def hmac_sign(data: str) -> str:
|
||||
"""Create HMAC-SHA256 signature."""
|
||||
return hmac.new(
|
||||
|
||||
Reference in New Issue
Block a user