feat: Add direct encrypted key testing for password in decryptAttachmentBlob function

This commit is contained in:
k1ngsterr1
2026-01-24 17:57:40 +05:00
parent 8c87b12c5f
commit 8fe0afea20
3 changed files with 155 additions and 42 deletions

View File

@@ -194,10 +194,16 @@ class MessageRepository private constructor(private val context: Context) {
scope.launch {
try {
// Шифрование
val (encryptedContent, encryptedKey) = MessageCrypto.encryptForSending(
val encryptResult = MessageCrypto.encryptForSending(
text.trim(),
toPublicKey
)
val encryptedContent = encryptResult.ciphertext
val encryptedKey = encryptResult.encryptedKey
// 🔑 КРИТИЧНО: Сохраняем ЗАШИФРОВАННЫЙ chacha_key (как в Desktop!)
// Desktop хранит зашифрованный ключ, расшифровывает только при использовании
android.util.Log.d("MessageRepository", "🔑 Outgoing chacha_key (encrypted): ${encryptedKey.length} chars")
// Сериализуем attachments в JSON
val attachmentsJson = serializeAttachments(attachments)
@@ -306,6 +312,11 @@ class MessageRepository private constructor(private val context: Context) {
val dialogKey = getDialogKey(packet.fromPublicKey)
try {
// 🔑 КРИТИЧНО: Сохраняем ЗАШИФРОВАННЫЙ chacha_key (как в Desktop!)
// Desktop: хранит зашифрованный ключ, расшифровывает только при использовании
// Buffer.from(await decrypt(message.chacha_key, privatePlain), "binary").toString('utf-8')
android.util.Log.d("MessageRepository", "🔑 Incoming chacha_key (encrypted): ${packet.chachaKey.length} chars")
// Расшифровываем
val plainText = MessageCrypto.decryptIncoming(
packet.content,