43 lines
1.3 KiB
Dart
43 lines
1.3 KiB
Dart
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)));
|
|
});
|
|
}
|