加解密性能优化,预埋
This commit is contained in:
@@ -23,11 +23,18 @@ class AuthNotifier extends ChangeNotifier {
|
||||
|
||||
void login() {
|
||||
_isLoggedIn = true;
|
||||
// TODO: 接入 cipher_guard_sdk 后,在此处完成 RSA 密钥注入:
|
||||
// 1. 从安全存储(keychain / secure storage)读取公私钥对(只读一次)
|
||||
// 2. cipherSdk.setActiveKeyPair(publicKey: pubPem, privateKey: privPem)
|
||||
// 须在 notifyListeners() 之前完成,确保路由跳转后 onEncryptRequest 回调触发时密钥已就绪。
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void logout() {
|
||||
_isLoggedIn = false;
|
||||
// TODO: 接入 cipher_guard_sdk 后,退出登录时清除内存密钥:
|
||||
// cipherSdk.clearActiveKeyPair()
|
||||
// cipherSdk.clearDerivedKeyCache()
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
@@ -37,9 +44,7 @@ class AuthNotifier extends ChangeNotifier {
|
||||
/// 使用 [Provider] 持有 [AuthNotifier] 单例。
|
||||
/// go_router 通过 [GoRouter.refreshListenable] 直接监听 [AuthNotifier](ChangeNotifier),
|
||||
/// Riverpod 侧不需要响应式更新(导航由 go_router 接管)。
|
||||
final authNotifierProvider = Provider<AuthNotifier>(
|
||||
(ref) => AuthNotifier(),
|
||||
);
|
||||
final authNotifierProvider = Provider<AuthNotifier>((ref) => AuthNotifier());
|
||||
|
||||
// ── 主题 ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -99,8 +99,24 @@ final apiConfigProvider = Provider<ApiConfig>((ref) {
|
||||
tokenStream.add(newToken);
|
||||
},
|
||||
onCheckNetworkAvailable: () async => networkMonitor.isConnected,
|
||||
onEncryptRequest: null, // TODO: 接入 cipher_guard_sdk 后注入请求加密回调
|
||||
onDecryptResponse: null, // TODO: 接入 cipher_guard_sdk 后注入响应解密回调
|
||||
// TODO: 接入 cipher_guard_sdk 后注入请求加密回调。
|
||||
// 前提:AuthNotifier.login() 中已完成 cipherSdk.setActiveKeyPair(pub, priv)。
|
||||
// 示例:
|
||||
// onEncryptRequest: (path, headers, body) async {
|
||||
// final encryptedKey = await cipherSdk.encryptSessionKeyWithActiveKey(
|
||||
// sessionKey: currentSessionKey,
|
||||
// );
|
||||
// return EncryptedRequest(body: encryptedBody, headers: {'X-Key': encryptedKey});
|
||||
// },
|
||||
onEncryptRequest: null,
|
||||
// TODO: 接入 cipher_guard_sdk 后注入响应解密回调。
|
||||
// 前提:与 onEncryptRequest 配套,服务端响应同样加密时启用。
|
||||
// 示例:
|
||||
// onDecryptResponse: (data) async {
|
||||
// final plaintext = await cipherSdk.decryptMessage(encryptedData: data as String, ...);
|
||||
// return jsonDecode(plaintext) as Map<String, dynamic>;
|
||||
// },
|
||||
onDecryptResponse: null,
|
||||
onBusinessError: null, // TODO: 接入业务错误统一处理(弹窗 / Toast / 跳转等)
|
||||
onTransformResponse:
|
||||
null, // TODO: 如后端响应格式非标准,在此归一化为 { code, data, message }
|
||||
|
||||
Reference in New Issue
Block a user