This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MessageListView( | |
messageBuilder: _messageBuilder, | |
) | |
----------- | |
Widget _messageBuilder( | |
BuildContext context, | |
MessageDetails details, | |
List<Message> messages, | |
) { | |
Message message = details.message; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MessageInput( | |
disableAttachments: true, | |
preMessageSending: (Message message) async { | |
String encryptedMessage = await AppE2EE().encrypt(message.text); | |
Message newmessage = message.copyWith(text: encryptedMessage); | |
return newmessage; | |
}, | |
), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> main() async { | |
WidgetsFlutterBinding. | |
(); | |
final client = StreamChatClient( | |
'ue75xxvdjwwa', | |
logLevel: Level. | |
, | |
); | |
await AppE2EE().generateKeys(); | |
Map<String, dynamic> publicKeyJwk = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
await AppE2EE().generateKeys(); | |
Map<String, dynamic> publicKeyJwk = | |
await AppE2EE().keyPair.publicKey.exportJsonWebKey(); | |
-------------------------------------- | |
await client.connectUser( | |
User( | |
id: 'Pinkesh', | |
extraData: { | |
'image': 'https://picsum.photos/id/1025/200/300', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:typed_data'; | |
import 'package:shared_preferences/shared_preferences.dart'; | |
import 'package:webcrypto/webcrypto.dart'; | |
class AppE2EE { | |
static final AppE2EE | |
= AppE2EE._internal(); | |
factory AppE2EE() { | |
return | |
; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<String> decrypt(String encryptedMessage) async { | |
// 1. | |
aesGcmSecretKey = await AesGcmSecretKey. | |
(derivedBits); | |
// 2. | |
List<int> message = Uint8List.fromList(encryptedMessage.codeUnits); | |
// 3. | |
Uint8List decryptdBytes = await aesGcmSecretKey.decryptBytes(message, iv); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final Uint8List iv = Uint8List.fromList('Initialization Vector'.codeUnits); | |
Future<String> encrypt(String message) async { | |
// 1. | |
aesGcmSecretKey = await AesGcmSecretKey. | |
(derivedBits); | |
// 2. | |
List<int> list = message.codeUnits; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> _deriveKey() async { | |
//1. Alice's public key | |
Map<String, dynamic> publicjwk = json.decode( | |
'{"kty": "EC", "crv": "P-256", "x": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "y": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}'); | |
EcdhPublicKey ecdhPublicKey = | |
await EcdhPublicKey. | |
(publicjwk, EllipticCurve.p256); | |
//2. Bob's private key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> _generateKeys() async { | |
//1. Generate keys | |
KeyPair<EcdhPrivateKey, EcdhPublicKey> keyPair = | |
await EcdhPrivateKey. | |
(EllipticCurve.p256); | |
Map<String, dynamic> publicKeyJwk = | |
await keyPair.publicKey.exportJsonWebKey(); | |
Map<String, dynamic> privateKeyJwk = | |
await keyPair.privateKey.exportJsonWebKey(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final theme = | |
ThemeData(primarySwatch: Colors.teal, brightness: Brightness.dark); | |
MaterialApp( | |
debugShowCheckedModeBanner: false, | |
theme: theme, | |
builder: (context, child) => StreamChat( | |
streamChatThemeData: StreamChatThemeData.fromTheme(theme), | |
client: client, | |
child: child, | |
), |
NewerOlder