我正在尝试将 Virgil e3 Kit 实施到我的 Flutter 应用程序中以进行端到端加密。当运行代码并在调试模式下注册时,EThree Kit 运行良好,但是当我尝试在发布模式下运行时,我在使用 EThree Kit 注册用户时遇到异常。
这是包:https://github.com/cardoso/virgil-e3kit-flutter
这是错误:
Failed to register user for encryption system: PlatformException(unknown_error, Http response: 400 : Bad Request Service response: 40200 : Identity search parameter cannot be empty., null, null)
我认为这与明文流量有关,所以我在我的 androidManifest 中启用了它,但它仍然不起作用
这是我调用的代码:
注册
final firebaseUser = await _firebaseAuth.createUserWithEmailAndPassword(
email: email, password: password);
await EncryptionUtils.initialize(_firebaseAuth.currentUser.uid);
await EncryptionUtils.register();
await EncryptionUtils.backupPrivateKey(
'${_firebaseAuth.currentUser.uid}...$password');
初始化
static Future<void> initialize(String uid) async {
if (_eThree != null) return;
final tokenCallback = () async {
final response = (await FirebaseFunctions.instance
.httpsCallable('getVirgilJwt')
.call())
.data;
final Map<String, dynamic> data = Map<String, dynamic>.from(response);
print('[encryption tokenCallback] - ${data['token']}');
return data['token'];
};
try {
if (uid == null || uid.isEmpty) {
throw Exception('user-id not valid');
}
_eThree = await EThree.init(uid, tokenCallback);
print('[ENCRYPTION UTILS] - (initialize) initialized successfully');
} catch (err) {
print('[ENCRYPTION UTILS] - Failed initializing: $err');
throw Exception('Failed to intialize end to end encryption system');
}
}
注册
static Future<void> register() async {
try {
await _eThree.cleanUp();
print('[ENCRYPTION UTILS] - (Register) cleaned up successfully');
} catch (err) {
print('[ENCRYPTION UTILS] - (Register) failed to cleanup');
}
try {
print(
'[encryption register] - trying to register ${await _eThree.identity}');
await _eThree.register();
print('[ENCRYPTION UTILS] - registered successfully');
} on PlatformException catch (err) {
if (err.code == 'user_is_already_registered') {
await _eThree.rotatePrivateKey();
print('Rotated private key instead');
}
print('Failed to register user for encryption system: $err');
throw Exception('Failed to register user for encryption system: $err');
}
}
先谢谢你!