Initial project

This commit is contained in:
Cody
2026-03-06 14:56:17 +08:00
parent 977b627b15
commit bf9e099747
1180 changed files with 50973 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
/// 加密 Repository 介面
/// 定義所有加密相關的操作
library;
import '../entities/rsa_key_pair.dart';
import '../entities/session_key.dart';
import '../entities/encrypted_message.dart';
abstract class EncryptionRepository {
// ==================== RSA 金鑰管理 ====================
/// 生成 RSA 金鑰對
/// [keySize] 金鑰長度 (預設 1024, 可用 2048)
Future<RsaKeyPair> generateRsaKeyPair({int keySize = 1024});
/// 用密碼加密私鑰
/// 返回 Base64 編碼的加密私鑰
Future<String> encryptPrivateKey({
required String privateKey,
required String password,
});
/// 解密私鑰
/// [encryptedPrivateKey] Base64 編碼的加密私鑰
/// [password] 用戶密碼
Future<String> decryptPrivateKey({
required String encryptedPrivateKey,
required String password,
});
// ==================== 會話金鑰管理 ====================
/// 生成 AES 會話金鑰 (32 字節)
Future<SessionKey> generateSessionKey({int initialRound});
/// 用 RSA 公鑰加密會話金鑰
/// 返回 Base64 編碼的加密會話金鑰
Future<String> encryptSessionKey({
required String sessionKey,
required String publicKey,
});
/// 用 RSA 私鑰解密會話金鑰
Future<String> decryptSessionKey({
required String encryptedSessionKey,
required String privateKey,
});
// ==================== 訊息加解密 ====================
/// 加密訊息
/// [plaintext] 原始訊息
/// [sessionKey] Base64 編碼的會話金鑰
/// [round] 金鑰 round 值
Future<EncryptedMessage> encryptMessage({
required String plaintext,
required String sessionKey,
required int round,
});
/// 解密訊息
/// [encryptedData] Base64 編碼的加密資料
/// [sessionKey] Base64 編碼的會話金鑰
/// [round] 金鑰 round 值
Future<String> decryptMessage({
required String encryptedData,
required String sessionKey,
required int round,
});
// ==================== 原生平台同步 ====================
/// 同步加密金鑰到原生平台 (iOS App Group)
Future<void> syncEncryptionKeysToNative({
required String chatId,
required int activeRound,
required int round,
required String activeKey,
required bool isSingle,
});
/// 批量同步所有加密聊天室的金鑰
Future<void> syncAllEncryptionKeys({
required Map<String, Map<String, dynamic>> chatMap,
});
// ==================== 配置相關 ====================
/// 設置 AES_SECRET (用於推送解密)
Future<void> setAesSecret({required String aesSecret});
/// 解密 APNS 推送通知內容
/// 使用 release.json 中的 AES_SECRET
Future<String?> decryptPushNotification({
required String encryptedData,
});
}