Finish implementing some encryption in the network protocols with AES
This commit is contained in:
parent
38eb7c6acd
commit
84cef345eb
10 changed files with 263 additions and 391 deletions
43
test/encryption_test.dart
Normal file
43
test/encryption_test.dart
Normal file
|
@ -0,0 +1,43 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:libac_dart/encryption/aes.dart';
|
||||
import 'package:libac_dart/encryption/xtea.dart';
|
||||
import 'package:libac_dart/utils/Hashing.dart';
|
||||
import 'package:test/expect.dart';
|
||||
import 'package:test/scaffolding.dart';
|
||||
|
||||
void main() {
|
||||
test("Test XTEA Encryption", () async {
|
||||
String knownEncryptedValue =
|
||||
"MU1T+AuHyBmALhbMOgZJQa5A"; // "Hello World!" // Test Key
|
||||
String keyHash = "131515d94e2574cd680ab1a41ecdc34c";
|
||||
List<int> knownKey = [320148953, 1311077581, 1745531300, 516801356];
|
||||
|
||||
XTEA tea = await XTEA("Test Key");
|
||||
expect(-1, tea.testKey(knownKey));
|
||||
|
||||
String newValue = tea.encryptString("Hello World!");
|
||||
|
||||
expect(Hashing.llMD5String("Test Key", 0), keyHash);
|
||||
expect(newValue, knownEncryptedValue);
|
||||
expect(tea.decryptString(newValue), "Hello World!");
|
||||
});
|
||||
|
||||
test("Test AES Implementation", () async {
|
||||
File key = File("test/aesKey.bin");
|
||||
File enc = File("test/HelloWorld.enc");
|
||||
File hw = File("test/HelloWorld.txt");
|
||||
String helloWorld = "Hello World!";
|
||||
|
||||
hw.writeAsStringSync(helloWorld);
|
||||
|
||||
AESCipher aes = await AESCipher.generate();
|
||||
AESData encryptedNew = await aes.encrypt(utf8.encode(helloWorld));
|
||||
|
||||
enc.writeAsBytes(encryptedNew.data);
|
||||
key.writeAsBytes(aes.getKey());
|
||||
|
||||
expect(helloWorld, utf8.decode(await aes.decrypt(encryptedNew)));
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue