INNER CODE UNIT · Python

ensure_crypto_key

sky22333/ansible-ui · app.py:77

def ensure_crypto_key():
    """确保运行期加密密钥已初始化"""
    from crypto_utils import CRYPTO_KEY

    if isinstance(CRYPTO_KEY, bytes) and len(CRYPTO_KEY) == 32:
        return True

    if not ADMIN_USERNAME or not ADMIN_PASSWORD:
        app.logger.error("缺少管理员凭证,无法派生加密密钥")
        return False

    app.logger.info("检测到加密密钥未初始化,尝试从管理员凭证派生")
    try:
        key, salt = derive_key_from_credentials(ADMIN_USERNAME, ADMIN_PASSWORD)
        set_crypto_keys(key, salt)
        app.logger.info("密钥派生成功,长度为: %d 字节", len(key))
        return True
    except Exception as e:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…