cas-typescript-sdk 1.0.15 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/main-pr-linux.yml +28 -0
- package/.github/workflows/main-pr-windows.yml +28 -0
- package/.github/workflows/main-publish.yml +32 -0
- package/Cargo.toml +8 -1
- package/README.md +5 -1
- package/build.rs +5 -5
- package/docs/EXAMPLES.md +39 -0
- package/index.d.ts +21 -0
- package/index.node +0 -0
- package/lib/digital-signature/digital-siganture-sha-512.d.ts +8 -0
- package/lib/digital-signature/digital-siganture-sha-512.js +46 -0
- package/lib/digital-signature/digital-signature-base.d.ts +7 -0
- package/lib/digital-signature/digital-signature-base.js +2 -0
- package/lib/digital-signature/digital-signature-factory.d.ts +8 -0
- package/lib/digital-signature/digital-signature-factory.js +22 -0
- package/lib/digital-signature/digital-signaturte-sha-256.d.ts +8 -0
- package/lib/digital-signature/digital-signaturte-sha-256.js +46 -0
- package/lib/digital-signature/index.d.ts +5 -0
- package/lib/digital-signature/index.js +11 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +6 -1
- package/package.json +41 -41
- package/src/asymmetric/cas_asymmetric_encryption.rs +15 -15
- package/src/asymmetric/cas_rsa.rs +88 -80
- package/src/digital_signature/cas_digital_signature_rsa.rs +27 -0
- package/src/digital_signature/sha_256_ed25519.rs +69 -0
- package/src/digital_signature/sha_256_rsa.rs +96 -0
- package/src/digital_signature/sha_512_ed25519.rs +75 -0
- package/src/digital_signature/sha_512_rsa.rs +93 -0
- package/src/hashers/blake2.rs +37 -39
- package/src/hashers/cas_hasher.rs +8 -8
- package/src/hashers/sha.rs +102 -103
- package/src/key_exchange/cas_key_exchange.rs +6 -6
- package/src/key_exchange/x25519.rs +57 -57
- package/src/lib.rs +35 -27
- package/src/password_hashers/argon2.rs +65 -64
- package/src/password_hashers/bcrypt.rs +50 -51
- package/src/password_hashers/cas_password_hasher.rs +4 -4
- package/src/password_hashers/scrypt.rs +61 -56
- package/src/symmetric/aes.rs +155 -151
- package/src/symmetric/cas_symmetric_encryption.rs +14 -14
- package/src-ts/asymmetric/RSAWrapper.ts +53 -53
- package/src-ts/asymmetric/index.ts +3 -3
- package/src-ts/digital-signature/digital-siganture-sha-512.ts +48 -0
- package/src-ts/digital-signature/digital-signature-base.ts +8 -0
- package/src-ts/digital-signature/digital-signature-factory.ts +19 -0
- package/src-ts/digital-signature/digital-signaturte-sha-256.ts +48 -0
- package/src-ts/digital-signature/index.ts +11 -0
- package/src-ts/hashers/hasher-base.ts +5 -5
- package/src-ts/hashers/hasher-factory.ts +11 -11
- package/src-ts/hashers/hasher-type.ts +2 -2
- package/src-ts/hashers/index.ts +5 -5
- package/src-ts/hashers/sha-wrapper.ts +37 -37
- package/src-ts/helpers/nonce-generator.ts +8 -8
- package/src-ts/hybrid/hybrid-encryption-wrapper.ts +64 -64
- package/src-ts/hybrid/index.ts +9 -9
- package/src-ts/hybrid/types/aes-rsa-hybird-encrypt-result.ts +12 -12
- package/src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts +23 -23
- package/src-ts/index.ts +44 -34
- package/src-ts/key_exchange/index.ts +3 -3
- package/src-ts/key_exchange/x25519.ts +10 -10
- package/src-ts/password-hashers/argon2-wrapper.ts +18 -18
- package/src-ts/password-hashers/bcrypt-wrapper.ts +23 -23
- package/src-ts/password-hashers/index.ts +14 -14
- package/src-ts/password-hashers/password-hasher-base.ts +3 -3
- package/src-ts/password-hashers/password-hasher-factory.ts +20 -20
- package/src-ts/password-hashers/password-hasher-type.ts +4 -4
- package/src-ts/password-hashers/scrypt-wrapper.ts +19 -19
- package/src-ts/symmetric/aes-wrapper.ts +50 -50
- package/src-ts/symmetric/index.ts +3 -3
- package/test-ts/asymmetric.test.spec.ts +27 -27
- package/test-ts/digital-signature.test.spec.ts +93 -0
- package/test-ts/hasher.test.spec.ts +70 -70
- package/test-ts/helpers/array.ts +9 -9
- package/test-ts/hybrid.test.spec.ts +33 -33
- package/test-ts/insecure-channel.test.spec.ts +50 -50
- package/test-ts/key-exchange-test.spec.ts +23 -23
- package/test-ts/password-hasher-test.spec.ts +102 -102
- package/test-ts/symmetric.test.spec.ts +31 -31
- package/tsconfig.json +21 -21
- package/build-node.sh +0 -2
- package/src-ts/global.d.ts +0 -2
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import {AESWrapper} from "../src-ts/symmetric/index";
|
|
2
|
-
import {X25519Wrapper} from "../src-ts/key_exchange/index";
|
|
3
|
-
import {X25519SecretPublicKeyResult} from "../index";
|
|
4
|
-
import { areEqual } from "./helpers/array";
|
|
5
|
-
import { assert } from "chai";
|
|
6
|
-
|
|
7
|
-
describe("Insecure Channel Tests", () => {
|
|
8
|
-
it("AES256-GBC Diffie Hellman X25519", () => {
|
|
9
|
-
const aesWrapper = new AESWrapper();
|
|
10
|
-
const x25519Wrapper = new X25519Wrapper();
|
|
11
|
-
const alice_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
12
|
-
const bob_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
13
|
-
|
|
14
|
-
const alice_shared_secret = x25519Wrapper.diffieHellman(alice_keys.secretKey, bob_keys.publicKey);
|
|
15
|
-
const bob_shared_secret = x25519Wrapper.diffieHellman(bob_keys.secretKey, alice_keys.publicKey);
|
|
16
|
-
|
|
17
|
-
const alice_aes_key = aesWrapper.aes256KeyFromX25519SharedSecret(alice_shared_secret);
|
|
18
|
-
const bob_aes_key = aesWrapper.aes256KeyFromX25519SharedSecret(bob_shared_secret);
|
|
19
|
-
|
|
20
|
-
const tohashed: string = "This is my encrypt text";
|
|
21
|
-
const encoder = new TextEncoder();
|
|
22
|
-
const toEncrypt: Array<number> = Array.from(encoder.encode(tohashed));
|
|
23
|
-
|
|
24
|
-
const encrypted = aesWrapper.aes256Encrypt(alice_aes_key?.aesKey, alice_aes_key?.aesNonce, toEncrypt);
|
|
25
|
-
const decrypted = aesWrapper.aes256Decrypt(bob_aes_key?.aesKey, bob_aes_key?.aesNonce, encrypted);
|
|
26
|
-
let result = areEqual(decrypted, toEncrypt);
|
|
27
|
-
assert.isTrue(result);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("AES128-GBC Diffie Hellman X25519", () => {
|
|
31
|
-
const aesWrapper = new AESWrapper();
|
|
32
|
-
const x25519Wrapper = new X25519Wrapper();
|
|
33
|
-
const alice_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
34
|
-
const bob_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
35
|
-
|
|
36
|
-
const alice_shared_secret = x25519Wrapper.diffieHellman(alice_keys.secretKey, bob_keys.publicKey);
|
|
37
|
-
const bob_shared_secret = x25519Wrapper.diffieHellman(bob_keys.secretKey, alice_keys.publicKey);
|
|
38
|
-
|
|
39
|
-
const alice_aes_key = aesWrapper.aes128KeyFromX25519SharedSecret(alice_shared_secret);
|
|
40
|
-
const bob_aes_key = aesWrapper.aes128KeyFromX25519SharedSecret(bob_shared_secret);
|
|
41
|
-
|
|
42
|
-
const tohashed: string = "This is my encrypt text";
|
|
43
|
-
const encoder = new TextEncoder();
|
|
44
|
-
const toEncrypt: Array<number> = Array.from(encoder.encode(tohashed));
|
|
45
|
-
|
|
46
|
-
const encrypted = aesWrapper.aes128Encrypt(alice_aes_key?.aesKey, alice_aes_key?.aesNonce, toEncrypt);
|
|
47
|
-
const decrypted = aesWrapper.aes128Decrypt(bob_aes_key?.aesKey, bob_aes_key?.aesNonce, encrypted);
|
|
48
|
-
let result = areEqual(decrypted, toEncrypt);
|
|
49
|
-
assert.isTrue(result);
|
|
50
|
-
});
|
|
1
|
+
import {AESWrapper} from "../src-ts/symmetric/index";
|
|
2
|
+
import {X25519Wrapper} from "../src-ts/key_exchange/index";
|
|
3
|
+
import {X25519SecretPublicKeyResult} from "../index";
|
|
4
|
+
import { areEqual } from "./helpers/array";
|
|
5
|
+
import { assert } from "chai";
|
|
6
|
+
|
|
7
|
+
describe("Insecure Channel Tests", () => {
|
|
8
|
+
it("AES256-GBC Diffie Hellman X25519", () => {
|
|
9
|
+
const aesWrapper = new AESWrapper();
|
|
10
|
+
const x25519Wrapper = new X25519Wrapper();
|
|
11
|
+
const alice_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
12
|
+
const bob_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
13
|
+
|
|
14
|
+
const alice_shared_secret = x25519Wrapper.diffieHellman(alice_keys.secretKey, bob_keys.publicKey);
|
|
15
|
+
const bob_shared_secret = x25519Wrapper.diffieHellman(bob_keys.secretKey, alice_keys.publicKey);
|
|
16
|
+
|
|
17
|
+
const alice_aes_key = aesWrapper.aes256KeyFromX25519SharedSecret(alice_shared_secret);
|
|
18
|
+
const bob_aes_key = aesWrapper.aes256KeyFromX25519SharedSecret(bob_shared_secret);
|
|
19
|
+
|
|
20
|
+
const tohashed: string = "This is my encrypt text";
|
|
21
|
+
const encoder = new TextEncoder();
|
|
22
|
+
const toEncrypt: Array<number> = Array.from(encoder.encode(tohashed));
|
|
23
|
+
|
|
24
|
+
const encrypted = aesWrapper.aes256Encrypt(alice_aes_key?.aesKey, alice_aes_key?.aesNonce, toEncrypt);
|
|
25
|
+
const decrypted = aesWrapper.aes256Decrypt(bob_aes_key?.aesKey, bob_aes_key?.aesNonce, encrypted);
|
|
26
|
+
let result = areEqual(decrypted, toEncrypt);
|
|
27
|
+
assert.isTrue(result);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("AES128-GBC Diffie Hellman X25519", () => {
|
|
31
|
+
const aesWrapper = new AESWrapper();
|
|
32
|
+
const x25519Wrapper = new X25519Wrapper();
|
|
33
|
+
const alice_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
34
|
+
const bob_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
35
|
+
|
|
36
|
+
const alice_shared_secret = x25519Wrapper.diffieHellman(alice_keys.secretKey, bob_keys.publicKey);
|
|
37
|
+
const bob_shared_secret = x25519Wrapper.diffieHellman(bob_keys.secretKey, alice_keys.publicKey);
|
|
38
|
+
|
|
39
|
+
const alice_aes_key = aesWrapper.aes128KeyFromX25519SharedSecret(alice_shared_secret);
|
|
40
|
+
const bob_aes_key = aesWrapper.aes128KeyFromX25519SharedSecret(bob_shared_secret);
|
|
41
|
+
|
|
42
|
+
const tohashed: string = "This is my encrypt text";
|
|
43
|
+
const encoder = new TextEncoder();
|
|
44
|
+
const toEncrypt: Array<number> = Array.from(encoder.encode(tohashed));
|
|
45
|
+
|
|
46
|
+
const encrypted = aesWrapper.aes128Encrypt(alice_aes_key?.aesKey, alice_aes_key?.aesNonce, toEncrypt);
|
|
47
|
+
const decrypted = aesWrapper.aes128Decrypt(bob_aes_key?.aesKey, bob_aes_key?.aesNonce, encrypted);
|
|
48
|
+
let result = areEqual(decrypted, toEncrypt);
|
|
49
|
+
assert.isTrue(result);
|
|
50
|
+
});
|
|
51
51
|
});
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { assert } from "chai";
|
|
2
|
-
import { X25519Wrapper } from "../src-ts/index";
|
|
3
|
-
import { areEqual } from "./helpers/array";
|
|
4
|
-
|
|
5
|
-
describe("X25519 Key Exchange", () => {
|
|
6
|
-
it("Pass", () => {
|
|
7
|
-
const wrapper = new X25519Wrapper();
|
|
8
|
-
const alice = wrapper.generateSecretAndPublicKey();
|
|
9
|
-
const bob = wrapper.generateSecretAndPublicKey();
|
|
10
|
-
|
|
11
|
-
const alice_shared_secret = wrapper.diffieHellman(
|
|
12
|
-
alice.secretKey,
|
|
13
|
-
bob.publicKey,
|
|
14
|
-
);
|
|
15
|
-
const bob_shared_secret = wrapper.diffieHellman(
|
|
16
|
-
bob.secretKey,
|
|
17
|
-
alice.publicKey,
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
var result = areEqual(alice_shared_secret, bob_shared_secret);
|
|
21
|
-
assert.isTrue(result);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
1
|
+
import { assert } from "chai";
|
|
2
|
+
import { X25519Wrapper } from "../src-ts/index";
|
|
3
|
+
import { areEqual } from "./helpers/array";
|
|
4
|
+
|
|
5
|
+
describe("X25519 Key Exchange", () => {
|
|
6
|
+
it("Pass", () => {
|
|
7
|
+
const wrapper = new X25519Wrapper();
|
|
8
|
+
const alice = wrapper.generateSecretAndPublicKey();
|
|
9
|
+
const bob = wrapper.generateSecretAndPublicKey();
|
|
10
|
+
|
|
11
|
+
const alice_shared_secret = wrapper.diffieHellman(
|
|
12
|
+
alice.secretKey,
|
|
13
|
+
bob.publicKey,
|
|
14
|
+
);
|
|
15
|
+
const bob_shared_secret = wrapper.diffieHellman(
|
|
16
|
+
bob.secretKey,
|
|
17
|
+
alice.publicKey,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
var result = areEqual(alice_shared_secret, bob_shared_secret);
|
|
21
|
+
assert.isTrue(result);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
import { assert, expect } from "chai";
|
|
2
|
-
import { BCryptWrapper } from "../src-ts/password-hashers/index";
|
|
3
|
-
import { ScryptWrapper } from "../src-ts/password-hashers/index";
|
|
4
|
-
import {
|
|
5
|
-
PasswordHasherFactory,
|
|
6
|
-
PasswordHasherType,
|
|
7
|
-
} from "../src-ts/password-hashers/";
|
|
8
|
-
|
|
9
|
-
describe("Bcrypt Tests", () => {
|
|
10
|
-
it("hash", () => {
|
|
11
|
-
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
12
|
-
const password: string = "ThisOneBadPassword!@";
|
|
13
|
-
const hashedPassword: string = hasher.hashPassword(password);
|
|
14
|
-
assert.notEqual(hashedPassword, password);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("verify pass", () => {
|
|
18
|
-
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
19
|
-
const password: string = "NotThisPassword!@";
|
|
20
|
-
const hashedPassword: string = hasher.hashPassword(password);
|
|
21
|
-
const isValid: boolean = hasher.verifyPassword(hashedPassword, password);
|
|
22
|
-
expect(isValid).to.equal(true);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("verify fail", () => {
|
|
26
|
-
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
27
|
-
const password: string = "NotThisPassword!@";
|
|
28
|
-
const hashedPassword: string = hasher.hashPassword(password);
|
|
29
|
-
const isValid: boolean = hasher.verifyPassword(
|
|
30
|
-
hashedPassword,
|
|
31
|
-
"ThesePasswordsDoNotMatch",
|
|
32
|
-
);
|
|
33
|
-
expect(isValid).to.equal(false);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe("Scrypt Tests", () => {
|
|
38
|
-
it("hash with factory", () => {
|
|
39
|
-
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
40
|
-
PasswordHasherType.Scrypt,
|
|
41
|
-
);
|
|
42
|
-
const password: string = "ScryptRocks";
|
|
43
|
-
const hashed: string = hasher.hashPassword(password);
|
|
44
|
-
assert.notEqual(password, hashed);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("verify pass with factory", () => {
|
|
48
|
-
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
49
|
-
PasswordHasherType.Scrypt,
|
|
50
|
-
);
|
|
51
|
-
const password: string = "ScryptRocks1231231";
|
|
52
|
-
const hashed: string = hasher.hashPassword(password);
|
|
53
|
-
const verified: boolean = hasher.verifyPassword(hashed, password);
|
|
54
|
-
assert.isTrue(verified);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("verify fail with factory", () => {
|
|
58
|
-
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
59
|
-
PasswordHasherType.Scrypt,
|
|
60
|
-
);
|
|
61
|
-
const password: string = "ScryptRocksSomeGarbageText";
|
|
62
|
-
const hashed: string = hasher.hashPassword(password);
|
|
63
|
-
const verified: boolean = hasher.verifyPassword(
|
|
64
|
-
hashed,
|
|
65
|
-
"make this fail, its not the same",
|
|
66
|
-
);
|
|
67
|
-
assert.isNotTrue(verified);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe("Argon2 Tests", () => {
|
|
72
|
-
it("hash with factory", () => {
|
|
73
|
-
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
74
|
-
PasswordHasherType.Argon2,
|
|
75
|
-
);
|
|
76
|
-
const password: string = "ScryptRocks";
|
|
77
|
-
const hashed: string = hasher.hashPassword(password);
|
|
78
|
-
assert.notEqual(password, hashed);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("verify pass with factory", () => {
|
|
82
|
-
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
83
|
-
PasswordHasherType.Argon2,
|
|
84
|
-
);
|
|
85
|
-
const password: string = "ScryptRocks1231231";
|
|
86
|
-
const hashed: string = hasher.hashPassword(password);
|
|
87
|
-
const verified: boolean = hasher.verifyPassword(hashed, password);
|
|
88
|
-
assert.isTrue(verified);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("verify fail with factory", () => {
|
|
92
|
-
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
93
|
-
PasswordHasherType.Argon2,
|
|
94
|
-
);
|
|
95
|
-
const password: string = "ScryptRocksSomeGarbageText";
|
|
96
|
-
const hashed: string = hasher.hashPassword(password);
|
|
97
|
-
const verified: boolean = hasher.verifyPassword(
|
|
98
|
-
hashed,
|
|
99
|
-
"make this fail, its not the same",
|
|
100
|
-
);
|
|
101
|
-
assert.isNotTrue(verified);
|
|
102
|
-
});
|
|
1
|
+
import { assert, expect } from "chai";
|
|
2
|
+
import { BCryptWrapper } from "../src-ts/password-hashers/index";
|
|
3
|
+
import { ScryptWrapper } from "../src-ts/password-hashers/index";
|
|
4
|
+
import {
|
|
5
|
+
PasswordHasherFactory,
|
|
6
|
+
PasswordHasherType,
|
|
7
|
+
} from "../src-ts/password-hashers/";
|
|
8
|
+
|
|
9
|
+
describe("Bcrypt Tests", () => {
|
|
10
|
+
it("hash", () => {
|
|
11
|
+
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
12
|
+
const password: string = "ThisOneBadPassword!@";
|
|
13
|
+
const hashedPassword: string = hasher.hashPassword(password);
|
|
14
|
+
assert.notEqual(hashedPassword, password);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("verify pass", () => {
|
|
18
|
+
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
19
|
+
const password: string = "NotThisPassword!@";
|
|
20
|
+
const hashedPassword: string = hasher.hashPassword(password);
|
|
21
|
+
const isValid: boolean = hasher.verifyPassword(hashedPassword, password);
|
|
22
|
+
expect(isValid).to.equal(true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("verify fail", () => {
|
|
26
|
+
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
27
|
+
const password: string = "NotThisPassword!@";
|
|
28
|
+
const hashedPassword: string = hasher.hashPassword(password);
|
|
29
|
+
const isValid: boolean = hasher.verifyPassword(
|
|
30
|
+
hashedPassword,
|
|
31
|
+
"ThesePasswordsDoNotMatch",
|
|
32
|
+
);
|
|
33
|
+
expect(isValid).to.equal(false);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("Scrypt Tests", () => {
|
|
38
|
+
it("hash with factory", () => {
|
|
39
|
+
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
40
|
+
PasswordHasherType.Scrypt,
|
|
41
|
+
);
|
|
42
|
+
const password: string = "ScryptRocks";
|
|
43
|
+
const hashed: string = hasher.hashPassword(password);
|
|
44
|
+
assert.notEqual(password, hashed);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("verify pass with factory", () => {
|
|
48
|
+
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
49
|
+
PasswordHasherType.Scrypt,
|
|
50
|
+
);
|
|
51
|
+
const password: string = "ScryptRocks1231231";
|
|
52
|
+
const hashed: string = hasher.hashPassword(password);
|
|
53
|
+
const verified: boolean = hasher.verifyPassword(hashed, password);
|
|
54
|
+
assert.isTrue(verified);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("verify fail with factory", () => {
|
|
58
|
+
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
59
|
+
PasswordHasherType.Scrypt,
|
|
60
|
+
);
|
|
61
|
+
const password: string = "ScryptRocksSomeGarbageText";
|
|
62
|
+
const hashed: string = hasher.hashPassword(password);
|
|
63
|
+
const verified: boolean = hasher.verifyPassword(
|
|
64
|
+
hashed,
|
|
65
|
+
"make this fail, its not the same",
|
|
66
|
+
);
|
|
67
|
+
assert.isNotTrue(verified);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe("Argon2 Tests", () => {
|
|
72
|
+
it("hash with factory", () => {
|
|
73
|
+
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
74
|
+
PasswordHasherType.Argon2,
|
|
75
|
+
);
|
|
76
|
+
const password: string = "ScryptRocks";
|
|
77
|
+
const hashed: string = hasher.hashPassword(password);
|
|
78
|
+
assert.notEqual(password, hashed);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("verify pass with factory", () => {
|
|
82
|
+
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
83
|
+
PasswordHasherType.Argon2,
|
|
84
|
+
);
|
|
85
|
+
const password: string = "ScryptRocks1231231";
|
|
86
|
+
const hashed: string = hasher.hashPassword(password);
|
|
87
|
+
const verified: boolean = hasher.verifyPassword(hashed, password);
|
|
88
|
+
assert.isTrue(verified);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("verify fail with factory", () => {
|
|
92
|
+
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
93
|
+
PasswordHasherType.Argon2,
|
|
94
|
+
);
|
|
95
|
+
const password: string = "ScryptRocksSomeGarbageText";
|
|
96
|
+
const hashed: string = hasher.hashPassword(password);
|
|
97
|
+
const verified: boolean = hasher.verifyPassword(
|
|
98
|
+
hashed,
|
|
99
|
+
"make this fail, its not the same",
|
|
100
|
+
);
|
|
101
|
+
assert.isNotTrue(verified);
|
|
102
|
+
});
|
|
103
103
|
});
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { assert } from "chai";
|
|
2
|
-
import { AESWrapper } from "../src-ts/symmetric/aes-wrapper";
|
|
3
|
-
import { areEqual } from "./helpers/array";
|
|
4
|
-
|
|
5
|
-
describe("Symmetric Tests", () => {
|
|
6
|
-
it("aes 128 encrypt and decrypt equals", () => {
|
|
7
|
-
const aesWrapper: AESWrapper = new AESWrapper();
|
|
8
|
-
const aesKey = aesWrapper.aes128Key();
|
|
9
|
-
const aesNonce = aesWrapper.aesNonce();
|
|
10
|
-
const tohashed: string = "This is my array to encrypt";
|
|
11
|
-
const encoder = new TextEncoder();
|
|
12
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
13
|
-
const ciphertext = aesWrapper.aes128Encrypt(aesKey, aesNonce, tohashBytes);
|
|
14
|
-
const plaintxt = aesWrapper.aes128Decrypt(aesKey, aesNonce, ciphertext);
|
|
15
|
-
var result = areEqual(plaintxt, tohashBytes);
|
|
16
|
-
assert.isTrue(result);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("aes 256 encrypt and decrypt equals", () => {
|
|
20
|
-
const aesWrapper: AESWrapper = new AESWrapper();
|
|
21
|
-
const aesKey = aesWrapper.aes256Key();
|
|
22
|
-
const aesNonce = aesWrapper.aesNonce();
|
|
23
|
-
const tohashed: string = "This is my array to encrypt";
|
|
24
|
-
const encoder = new TextEncoder();
|
|
25
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
26
|
-
const ciphertext = aesWrapper.aes256Encrypt(aesKey, aesNonce, tohashBytes);
|
|
27
|
-
const plaintxt = aesWrapper.aes256Decrypt(aesKey, aesNonce, ciphertext);
|
|
28
|
-
var result = areEqual(plaintxt, tohashBytes);
|
|
29
|
-
assert.isTrue(result);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
1
|
+
import { assert } from "chai";
|
|
2
|
+
import { AESWrapper } from "../src-ts/symmetric/aes-wrapper";
|
|
3
|
+
import { areEqual } from "./helpers/array";
|
|
4
|
+
|
|
5
|
+
describe("Symmetric Tests", () => {
|
|
6
|
+
it("aes 128 encrypt and decrypt equals", () => {
|
|
7
|
+
const aesWrapper: AESWrapper = new AESWrapper();
|
|
8
|
+
const aesKey = aesWrapper.aes128Key();
|
|
9
|
+
const aesNonce = aesWrapper.aesNonce();
|
|
10
|
+
const tohashed: string = "This is my array to encrypt";
|
|
11
|
+
const encoder = new TextEncoder();
|
|
12
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
13
|
+
const ciphertext = aesWrapper.aes128Encrypt(aesKey, aesNonce, tohashBytes);
|
|
14
|
+
const plaintxt = aesWrapper.aes128Decrypt(aesKey, aesNonce, ciphertext);
|
|
15
|
+
var result = areEqual(plaintxt, tohashBytes);
|
|
16
|
+
assert.isTrue(result);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("aes 256 encrypt and decrypt equals", () => {
|
|
20
|
+
const aesWrapper: AESWrapper = new AESWrapper();
|
|
21
|
+
const aesKey = aesWrapper.aes256Key();
|
|
22
|
+
const aesNonce = aesWrapper.aesNonce();
|
|
23
|
+
const tohashed: string = "This is my array to encrypt";
|
|
24
|
+
const encoder = new TextEncoder();
|
|
25
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
26
|
+
const ciphertext = aesWrapper.aes256Encrypt(aesKey, aesNonce, tohashBytes);
|
|
27
|
+
const plaintxt = aesWrapper.aes256Decrypt(aesKey, aesNonce, ciphertext);
|
|
28
|
+
var result = areEqual(plaintxt, tohashBytes);
|
|
29
|
+
assert.isTrue(result);
|
|
30
|
+
});
|
|
31
|
+
});
|
package/tsconfig.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
-
"display": "Node 18",
|
|
4
|
-
|
|
5
|
-
"compilerOptions": {
|
|
6
|
-
"lib": ["es2022"],
|
|
7
|
-
"module": "commonjs",
|
|
8
|
-
"target": "es2022",
|
|
9
|
-
|
|
10
|
-
"strict": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"skipLibCheck": true,
|
|
13
|
-
"forceConsistentCasingInFileNames": true,
|
|
14
|
-
|
|
15
|
-
"outDir": "lib",
|
|
16
|
-
"declaration": true
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
"include": [
|
|
20
|
-
"src-ts/**/*"
|
|
21
|
-
]
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"display": "Node 18",
|
|
4
|
+
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"lib": ["es2022"],
|
|
7
|
+
"module": "commonjs",
|
|
8
|
+
"target": "es2022",
|
|
9
|
+
|
|
10
|
+
"strict": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"forceConsistentCasingInFileNames": true,
|
|
14
|
+
|
|
15
|
+
"outDir": "lib",
|
|
16
|
+
"declaration": true
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
"include": [
|
|
20
|
+
"src-ts/**/*"
|
|
21
|
+
]
|
|
22
22
|
}
|
package/build-node.sh
DELETED
package/src-ts/global.d.ts
DELETED