Tom*_*ard 5 encryption aes dart flutter end-to-end-encryption
我正在制作一个聊天应用程序,其中:
\n我用来firebase-realtime-database存储数据。
为每个用户随机生成密钥
\nString generateEncryptionKey(int len) {\n var r = Random();\n String randomString = String.fromCharCodes(List.generate(len,\n (index) => r.nextInt(33) + 89));\n return randomString;\n}\nRun Code Online (Sandbox Code Playgroud)\n这可能是错误的。derived key如果我需要从用户的密码中获取密码或者这是否足够,我需要澄清。
shared-secret key)shared-secret keyshared-secret key每个个人密钥都有一些共同点,对吧?因此,任何参与者加密的消息都可以被任何其他参与者解密。
我怎样才能生成shared-secret key?
generateKeyPair() {\n // Generate a private - public keypair for each user\n // ...somehow used to make the `shared-secret key`?\n}\n\ngenerateSharedSecretKey() {\n // Saved to database as the group\'s shared secret key.\n // only participants can use it to decrypt messages\n}\n\nsendMessage() {\n // 1. Encrypt the message (**code needed**)...using\n // which combination of keys?\n // 2. Save to database (I already handle this)\n}\n\nreceiveMessage() {\n // 1. Read from database (I already handle this)\n // 2. Decrypt the message (**code needed**)...using\n // which combination of keys?\n}\nRun Code Online (Sandbox Code Playgroud)\n我已经阅读过有关Diffie\xe2\x80\x93Hellman 密钥交换、密钥对等的内容。但我并不真正理解所有概念,因为我很新。
\n我会需要:
\n我只想通过数据库对多个用户的简单数据(字符串)进行加密。有没有比端到端更简单的方法?
\n群聊
首先,组管理员(或创建组的人员)必须为组生成一个密钥。这使用对称加密,其中使用单个密钥进行解密和加密。该密钥应与所有参与者共享。
当参与者想要发送消息时,使用此密钥对其进行加密并将其发送到服务器,服务器只需将其重新传输到参与者的收件箱即可。
由于用户 2 和 3 已经拥有共享密钥,因此他们在客户端对其进行解密。这种加密有很多选择,您可以通过 google 搜索任何“对称加密算法”(例如:AES)并选择 pub.dev 上提供的一种。
注意事项:
编辑:如果您想加密共享密钥的传输,您可以利用现有的 1 对 1 架构,并且组管理员可以通过使用参与者公钥加密来将密钥发送给每个参与者(当然他们会解密)。只要您在发送方正确处理 sendGroupSharedSecretKeyToParticipants() 并在接收方正确处理 onReceiveGroupSharedSecretKey() ,就应该没问题。这可能会使事情变得有点复杂(共享密钥的处理与典型的聊天消息不同),但这将是一种简单的方法。
1对1聊天
每个用户都可以拥有一个私钥和一个公钥,消息是通过使用接收者公钥加密来发送的,接收者将使用自己的私钥对其进行解密,这是非常基本的东西,您已经弄清楚或参考@Jabbar的答案/sf/answers/5236671751/
| 归档时间: |
|
| 查看次数: |
1240 次 |
| 最近记录: |