Skip to content

Commit

Permalink
[Feature/RSA] rbavo it works
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannBrglt committed Oct 6, 2023
1 parent 3789d63 commit 76ca1ce
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions client_flutter/lib/core/repository/kara_repo.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:convert';
import 'dart:developer';
import 'dart:typed_data';
import 'package:convert/convert.dart';

import 'package:encrypt/encrypt.dart';
import 'package:kar_assistant/core/models/kara_response.dart';
Expand All @@ -20,35 +22,31 @@ class KaraRepo implements KaraRepository {
jsonData['date'] = DateTime.now().toUtc().toIso8601String();

String dataString = jsonEncode(jsonData);

final key = Key.fromSecureRandom(16);
final iv = IV.fromSecureRandom(16);
Encrypted dataEncrypted =
UtilsController().encryptAES(dataString, key, iv);
String dataAes = '{"key":"${key.base64}","iv":"${iv.base64}"}';
Encrypted dataAesEncrypted = await UtilsController().encryptRSA(dataAes);
Map<String, dynamic> data = {
'data': dataEncrypted.base64,
'data': hex.encode(dataEncrypted.bytes),
'aes': dataAesEncrypted.base64,
};
String dataAesDecrypted =
await UtilsController().decryptRSA(Encrypted.from64(data['aes']));
print(dataAesDecrypted);

final response = await HttpRepo().getRequestParams("api/heyKara", data);
var parsedResponse = jsonDecode(response.body);

String dataAesDecrypted = await UtilsController()
.decryptRSA(Encrypted.fromBase64(parsedResponse['aes']));
var jsonDataAes = jsonDecode(dataAesDecrypted);
print(jsonDataAes['iv']);
String message = UtilsController().decryptAES(
Encrypted.from64(data['data']),
Encrypted(hex.decode(parsedResponse['data']) as Uint8List),
Key.fromBase64(jsonDataAes['key']),
IV.fromBase64(jsonDataAes['iv']),
);
print('secondData: $message');
Map<String, String> value = jsonDecode(message);
print(value.toString());

print(value);
final response = await HttpRepo().getRequestParams("api/heyKara", data);
final parsedResponse = KaraResponse.fromJson(jsonDecode(response.body));
return parsedResponse;
Map<String, dynamic> value = jsonDecode(message);
KaraResponse karaResponse = KaraResponse.fromJson(value);
return karaResponse;
} catch (err) {
rethrow;
}
Expand Down

0 comments on commit 76ca1ce

Please sign in to comment.