feat: Simplify AES key encryption and decryption process in MessageCrypto by removing unnecessary conversions and enhancing logging

This commit is contained in:
k1ngsterr1
2026-01-11 01:42:29 +05:00
parent 284731fc43
commit 569127100f
3 changed files with 278 additions and 13 deletions

View File

@@ -186,10 +186,13 @@ fun encryptWithPassword(data: String, password: String): String
**Алгоритм:**
```
1. Сжатие данных (Deflate)
1. Сжатие данных (zlib Deflate)
data → compressed bytes
(совместимо с pako.deflate в JS)
2. Деривация ключа (PBKDF2-HMAC-SHA256)
2. Деривация ключа (PBKDF2-HMAC-SHA1)
⚠️ ВАЖНО: SHA1, не SHA256!
(crypto-js по умолчанию использует SHA1)
password + "rosetta" salt + 1000 iterations
→ 256-bit AES key
@@ -205,6 +208,19 @@ fun encryptWithPassword(data: String, password: String): String
"aGVsbG8=:d29ybGQ="
```
**Кросс-платформенная совместимость:**
| Параметр | JS (crypto-js) | Kotlin |
| ----------- | -------------- | ----------------- |
| PBKDF2 | HMAC-SHA1 | HMAC-SHA1 ✅ |
| Salt | "rosetta" | "rosetta" ✅ |
| Iterations | 1000 | 1000 ✅ |
| Key size | 256 bit | 256 bit ✅ |
| Cipher | AES-256-CBC | AES-256-CBC ✅ |
| Padding | PKCS7 | PKCS5 (=PKCS7) ✅ |
| Compression | pako.deflate | Deflater ✅ |
| Format | iv:ct (base64) | iv:ct (base64) ✅ |
**Зачем сжатие?**
- Seed phrase (12 слов ≈ 100 байт) → ~50 байт после сжатия