Task: Fixed aes and tests

This commit is contained in:
Sambo Chea 2022-02-14 18:41:48 +07:00
parent f071f99346
commit 9d89ac0b1e
Signed by: sombochea
GPG Key ID: 3C7CF22A05D95490
7 changed files with 26 additions and 10 deletions

4
dummy/aes-256.keys.json Normal file
View File

@ -0,0 +1,4 @@
{
"keyPath": "./dummy/aes-256-32.key",
"ivPath": "./dummy/aes-256-16.key"
}

View File

@ -1,4 +0,0 @@
{
"keyPath": "./dummy/ase-256-32.key",
"ivPath": "./dummy/ase-256-16.key"
}

View File

@ -7,8 +7,8 @@ import {
// DefaultCryptoProvider
const key = "67rKmuc6DiDukE0jsUP421Eizo4CreaL6Q7Pg/NmH/s="
const iv = "FEFM9AY2m5jDq6GZ+CfLIA=="
const keyJsonFileValuesDefault = "./dummy/ase-256.json"
const keyJsonFileKeysDefault = "./dummy/ase-256.keys.json"
const keyJsonFileValuesDefault = "./dummy/aes-256.json"
const keyJsonFileKeysDefault = "./dummy/aes-256.keys.json"
// E2ECryptoProvider
const PRIVATE_KEY_VALUE =
@ -36,6 +36,22 @@ test("test: Default Encryption From Values", () => {
expect(decrypted).toBe(TEXT)
})
test("test: Default Encryption with Hello World", () => {
const data = "Hello World"
const provider = CryptoProvider.newInstance(
new DefaultCryptoProvider({
key: key,
iv: iv,
})
)
const encrypted = provider.encrypt(data)
const decrypted = provider.decrypt(encrypted)
const decrypted2 = provider.decrypt("6Rkfueq+fT3vPgWTST1lXg==")
expect(decrypted).toBe(data)
expect(decrypted2).toBe(data)
})
test("test: Default Encryption From JsonFile Values", () => {
const provider = CryptoProvider.newInstance(
new DefaultCryptoProvider({

View File

@ -4,15 +4,15 @@ const key = "67rKmuc6DiDukE0jsUP421Eizo4CreaL6Q7Pg/NmH/s="
const iv = "FEFM9AY2m5jDq6GZ+CfLIA=="
test("test: readFileToString", () => {
const value1 = readFileToString("./dummy/ase-256-32.key")
const value2 = readFileToString("./dummy/ase-256-16.key")
const value1 = readFileToString("./dummy/aes-256-32.key")
const value2 = readFileToString("./dummy/aes-256-16.key")
expect(value1).toBe(key)
expect(value2).toBe(iv)
})
test("test: readFileToString with jsonFile key-paths", () => {
const json = readFileToJson("./dummy/ase-256.keys.json")
const json = readFileToJson("./dummy/aes-256.keys.json")
const value1 = readFileToString(json.keyPath)
const value2 = readFileToString(json.ivPath)
expect(value1).toBe(key)
@ -20,7 +20,7 @@ test("test: readFileToString with jsonFile key-paths", () => {
})
test("test: readFileToString with jsonFile values", () => {
const json = readFileToJson("./dummy/ase-256.json")
const json = readFileToJson("./dummy/aes-256.json")
const value1 = json.key
const value2 = json.iv
expect(value1).toBe(key)