сборка: APK (Android) + Linux Desktop
- Исправлены ошибки Flutter анализа (withOpacity, pbkdf2, импорты) - Упрощён pubspec.yaml (только нужные зависимости) - Android APK собран: build/app/outputs/flutter-apk/app-release.apk (22MB) - Linux Desktop собран: build/linux/x64/release/bundle/jam_client Для Windows: кросс-компиляция невозможна с Linux. Нужен Windows хост для flutter build windows.
This commit is contained in:
@@ -2,7 +2,7 @@ import 'dart:convert';
|
||||
import 'dart:math';
|
||||
import 'dart:typed_data';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:pointycastle/export.dart' as pc;
|
||||
|
||||
|
||||
class CryptoService {
|
||||
static const int keySize = 32;
|
||||
@@ -28,20 +28,40 @@ class CryptoService {
|
||||
}
|
||||
|
||||
Uint8List deriveKey(String password, Uint8List salt) {
|
||||
final key = pbkdf2(
|
||||
hash: sha256,
|
||||
password: utf8.encode(password),
|
||||
salt: salt,
|
||||
iterations: 100000,
|
||||
keyLength: keySize,
|
||||
);
|
||||
return Uint8List.fromList(key);
|
||||
return _pbkdf2(sha256, utf8.encode(password), salt, 100000, keySize);
|
||||
}
|
||||
|
||||
static Uint8List _pbkdf2(Hash hash, List<int> password, List<int> salt, int iterations, int keyLength) {
|
||||
const hLen = 32;
|
||||
final blocks = (keyLength + hLen - 1) ~/ hLen;
|
||||
final result = Uint8List(keyLength);
|
||||
|
||||
for (int block = 1; block <= blocks; block++) {
|
||||
final blockBytes = ByteData(4)..setUint32(0, block, Endian.big);
|
||||
final blockSalt = Uint8List.fromList([...salt, ...blockBytes.buffer.asUint8List()]);
|
||||
final prf = Hmac(hash, password);
|
||||
var u = prf.convert(blockSalt).bytes;
|
||||
var t = Uint8List.fromList(u);
|
||||
|
||||
for (int i = 1; i < iterations; i++) {
|
||||
u = prf.convert(u).bytes;
|
||||
for (int j = 0; j < hLen; j++) {
|
||||
t[j] ^= u[j];
|
||||
}
|
||||
}
|
||||
|
||||
final offset = (block - 1) * hLen;
|
||||
final length = min(hLen, keyLength - offset);
|
||||
result.setRange(offset, offset + length, t.sublist(0, length));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Uint8List encrypt(Uint8List plaintext, Uint8List key) {
|
||||
final nonce = generateNonce();
|
||||
final hmac = Hmac(sha256, key);
|
||||
final mac = hmac.convert(plaintext).bytes;
|
||||
final nonce = generateNonce();
|
||||
|
||||
final result = Uint8List(nonce.length + mac.length + plaintext.length);
|
||||
result.setAll(0, nonce);
|
||||
@@ -54,7 +74,6 @@ class CryptoService {
|
||||
Uint8List? decrypt(Uint8List ciphertext, Uint8List key) {
|
||||
try {
|
||||
if (ciphertext.length < nonceSize + 32) return null;
|
||||
final nonce = ciphertext.sublist(0, nonceSize);
|
||||
final mac = ciphertext.sublist(nonceSize, nonceSize + 32);
|
||||
final plaintext = ciphertext.sublist(nonceSize + 32);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user