feat: enhance message encryption and media file conversion with improved compression and base64 encoding

This commit is contained in:
2026-02-15 15:45:56 +05:00
parent b543ef4d6f
commit 185ae3ad1d
2 changed files with 16 additions and 11 deletions

View File

@@ -762,10 +762,14 @@ object MessageCrypto {
val deflater = java.util.zip.Deflater()
deflater.setInput(replyJson.toByteArray(Charsets.UTF_8))
deflater.finish()
val compressedBuffer = ByteArray(replyJson.length * 2 + 100)
val compressedSize = deflater.deflate(compressedBuffer)
val outputStream = java.io.ByteArrayOutputStream()
val buffer = ByteArray(8192)
while (!deflater.finished()) {
val count = deflater.deflate(buffer)
outputStream.write(buffer, 0, count)
}
deflater.end()
val compressed = compressedBuffer.copyOf(compressedSize)
val compressed = outputStream.toByteArray()
// PBKDF2 key derivation (matching crypto-js: crypto.PBKDF2(password, 'rosetta', {keySize: 256/32, iterations: 1000}))
// Используем generatePBKDF2Key() для совместимости с crypto-js (UTF-8 encoding)
@@ -789,8 +793,8 @@ object MessageCrypto {
result
} catch (e: Exception) {
// Fallback: return plaintext (for backwards compatibility)
replyJson
android.util.Log.e("MessageCrypto", "encryptReplyBlob failed", e)
throw e
}
}

View File

@@ -172,7 +172,8 @@ object MediaUtils {
val bytes = inputStream.readBytes()
inputStream.close()
val base64 = Base64.encodeToString(bytes, Base64.NO_WRAP)
val mimeType = context.contentResolver.getType(uri) ?: "application/octet-stream"
val base64 = "data:$mimeType;base64," + Base64.encodeToString(bytes, Base64.NO_WRAP)
base64
} catch (e: Exception) {