cas-typescript-sdk 1.0.14 → 1.0.16
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 +3 -1
- package/build.rs +5 -5
- package/docs/EXAMPLES.md +39 -0
- package/index.d.ts +19 -0
- package/index.node +0 -0
- package/lib/digital-signature/digital-siganture-sha-512.d.ts +6 -0
- package/lib/digital-signature/digital-siganture-sha-512.js +28 -0
- package/lib/digital-signature/digital-signature-base.d.ts +5 -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 +6 -0
- package/lib/digital-signature/digital-signaturte-sha-256.js +28 -0
- package/lib/digital-signature/index.d.ts +4 -0
- package/lib/digital-signature/index.js +8 -0
- package/lib/hybrid/hybrid-encryption-wrapper.d.ts +9 -0
- package/lib/hybrid/hybrid-encryption-wrapper.js +30 -0
- package/lib/hybrid/index.d.ts +4 -0
- package/lib/hybrid/index.js +9 -0
- package/lib/hybrid/types/aes-rsa-hybird-encrypt-result.d.ts +7 -0
- package/lib/hybrid/types/aes-rsa-hybird-encrypt-result.js +16 -0
- package/lib/hybrid/types/aes-rsa-hybrid-initializer.d.ts +8 -0
- package/lib/hybrid/types/aes-rsa-hybrid-initializer.js +25 -0
- package/lib/index.d.ts +3 -2
- package/lib/index.js +8 -4
- package/package.json +41 -39
- 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_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 +34 -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 +28 -0
- package/src-ts/digital-signature/digital-signature-base.ts +6 -0
- package/src-ts/digital-signature/digital-signature-factory.ts +19 -0
- package/src-ts/digital-signature/digital-signaturte-sha-256.ts +28 -0
- package/src-ts/digital-signature/index.ts +4 -0
- package/src-ts/global.d.ts +1 -1
- 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 -0
- package/src-ts/hybrid/index.ts +9 -0
- package/src-ts/hybrid/types/aes-rsa-hybird-encrypt-result.ts +13 -0
- package/src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts +24 -0
- package/src-ts/index.ts +34 -26
- 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 +49 -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 -0
- 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/lib/cas_core_lib.dll +0 -0
- package/lib/hashers/IHasherBase.d.ts +0 -6
- package/lib/hashers/SHAWrapper.d.ts +0 -7
- package/lib/hashers/SHAWrapper.js +0 -37
- package/lib/libcas_core_lib.so +0 -0
- package/lib/password-hashers/types/argon2-hash-thread-result.d.ts +0 -3
- package/lib/password-hashers/types/argon2-hash-thread-result.js +0 -11
- /package/lib/{hashers/IHasherBase.js → digital-signature/digital-signature-base.js} +0 -0
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AesKeyFromX25519SharedSecret,
|
|
3
|
-
aes128Decrypt,
|
|
4
|
-
aes128Encrypt,
|
|
5
|
-
aes128Key,
|
|
6
|
-
aes128KeyFromX25519SharedSecret,
|
|
7
|
-
aes256Decrypt,
|
|
8
|
-
aes256Encrypt,
|
|
9
|
-
aes256Key,
|
|
10
|
-
aes256KeyFromX25519SharedSecret,
|
|
11
|
-
aesNonce,
|
|
12
|
-
} from "../../index";
|
|
13
|
-
|
|
14
|
-
export class AESWrapper {
|
|
15
|
-
public aes128Key(): Array<number> {
|
|
16
|
-
return aes128Key();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public aes256Key(): Array<number> {
|
|
20
|
-
return aes256Key();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public aesNonce(): Array<number> {
|
|
24
|
-
return aesNonce();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public aes128Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number> {
|
|
28
|
-
return aes128Encrypt(aesKey, nonce, plaintext);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public aes128Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number> {
|
|
32
|
-
return aes128Decrypt(aesKey, nonce, ciphertext);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public aes256Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number> {
|
|
36
|
-
return aes256Encrypt(aesKey, nonce, plaintext);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public aes256Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number> {
|
|
40
|
-
return aes256Decrypt(aesKey, nonce, ciphertext);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public aes256KeyFromX25519SharedSecret(shared_secret: Array<number>): AesKeyFromX25519SharedSecret {
|
|
44
|
-
return aes256KeyFromX25519SharedSecret(shared_secret);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public aes128KeyFromX25519SharedSecret(shared_secret: Array<number>): AesKeyFromX25519SharedSecret {
|
|
48
|
-
return aes128KeyFromX25519SharedSecret(shared_secret);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
AesKeyFromX25519SharedSecret,
|
|
3
|
+
aes128Decrypt,
|
|
4
|
+
aes128Encrypt,
|
|
5
|
+
aes128Key,
|
|
6
|
+
aes128KeyFromX25519SharedSecret,
|
|
7
|
+
aes256Decrypt,
|
|
8
|
+
aes256Encrypt,
|
|
9
|
+
aes256Key,
|
|
10
|
+
aes256KeyFromX25519SharedSecret,
|
|
11
|
+
aesNonce,
|
|
12
|
+
} from "../../index";
|
|
13
|
+
|
|
14
|
+
export class AESWrapper {
|
|
15
|
+
public aes128Key(): Array<number> {
|
|
16
|
+
return aes128Key();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public aes256Key(): Array<number> {
|
|
20
|
+
return aes256Key();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public aesNonce(): Array<number> {
|
|
24
|
+
return aesNonce();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public aes128Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number> {
|
|
28
|
+
return aes128Encrypt(aesKey, nonce, plaintext);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public aes128Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number> {
|
|
32
|
+
return aes128Decrypt(aesKey, nonce, ciphertext);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public aes256Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number> {
|
|
36
|
+
return aes256Encrypt(aesKey, nonce, plaintext);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public aes256Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number> {
|
|
40
|
+
return aes256Decrypt(aesKey, nonce, ciphertext);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public aes256KeyFromX25519SharedSecret(shared_secret: Array<number>): AesKeyFromX25519SharedSecret {
|
|
44
|
+
return aes256KeyFromX25519SharedSecret(shared_secret);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public aes128KeyFromX25519SharedSecret(shared_secret: Array<number>): AesKeyFromX25519SharedSecret {
|
|
48
|
+
return aes128KeyFromX25519SharedSecret(shared_secret);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { AESWrapper } from "./aes-wrapper";
|
|
2
|
-
|
|
3
|
-
export { AESWrapper };
|
|
1
|
+
import { AESWrapper } from "./aes-wrapper";
|
|
2
|
+
|
|
3
|
+
export { AESWrapper };
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { assert } from "chai";
|
|
2
|
-
import { RSAWrapper, RsaKeyPairResult } from "..";
|
|
3
|
-
import { areEqual } from "./helpers/array";
|
|
4
|
-
|
|
5
|
-
describe("Asymmetric Tests", () => {
|
|
6
|
-
it("RSA 4096 encrypt and decrypt equals", () => {
|
|
7
|
-
const rsaWrapper: RSAWrapper = new RSAWrapper();
|
|
8
|
-
const keys: RsaKeyPairResult = rsaWrapper.generateKeys(4096);
|
|
9
|
-
const tohashed: string = "This is my array to encrypt";
|
|
10
|
-
const encoder = new TextEncoder();
|
|
11
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
12
|
-
const ciphertext = rsaWrapper.encrypt(keys.publicKey, tohashBytes);
|
|
13
|
-
const plaintext = rsaWrapper.decrypt(keys.privateKey, ciphertext);
|
|
14
|
-
let result = areEqual(tohashBytes, plaintext);
|
|
15
|
-
assert.isTrue(result);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("RSA 2048 Sign and Verify", () => {
|
|
19
|
-
const rsaWrapper = new RSAWrapper();
|
|
20
|
-
const keys: RsaKeyPairResult = rsaWrapper.generateKeys(2048);
|
|
21
|
-
const tohashed: string = "This is my encrypt";
|
|
22
|
-
const encoder = new TextEncoder();
|
|
23
|
-
const toSignBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
24
|
-
const signature: Array<number> = rsaWrapper.sign(keys.privateKey, toSignBytes);
|
|
25
|
-
const verified = rsaWrapper.verify(keys.publicKey, toSignBytes, signature);
|
|
26
|
-
assert.isTrue(verified);
|
|
27
|
-
});
|
|
1
|
+
import { assert } from "chai";
|
|
2
|
+
import { RSAWrapper, RsaKeyPairResult } from "..";
|
|
3
|
+
import { areEqual } from "./helpers/array";
|
|
4
|
+
|
|
5
|
+
describe("Asymmetric Tests", () => {
|
|
6
|
+
it("RSA 4096 encrypt and decrypt equals", () => {
|
|
7
|
+
const rsaWrapper: RSAWrapper = new RSAWrapper();
|
|
8
|
+
const keys: RsaKeyPairResult = rsaWrapper.generateKeys(4096);
|
|
9
|
+
const tohashed: string = "This is my array to encrypt";
|
|
10
|
+
const encoder = new TextEncoder();
|
|
11
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
12
|
+
const ciphertext = rsaWrapper.encrypt(keys.publicKey, tohashBytes);
|
|
13
|
+
const plaintext = rsaWrapper.decrypt(keys.privateKey, ciphertext);
|
|
14
|
+
let result = areEqual(tohashBytes, plaintext);
|
|
15
|
+
assert.isTrue(result);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("RSA 2048 Sign and Verify", () => {
|
|
19
|
+
const rsaWrapper = new RSAWrapper();
|
|
20
|
+
const keys: RsaKeyPairResult = rsaWrapper.generateKeys(2048);
|
|
21
|
+
const tohashed: string = "This is my encrypt";
|
|
22
|
+
const encoder = new TextEncoder();
|
|
23
|
+
const toSignBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
24
|
+
const signature: Array<number> = rsaWrapper.sign(keys.privateKey, toSignBytes);
|
|
25
|
+
const verified = rsaWrapper.verify(keys.publicKey, toSignBytes, signature);
|
|
26
|
+
assert.isTrue(verified);
|
|
27
|
+
});
|
|
28
28
|
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { assert } from "chai";
|
|
2
|
+
import { DigitalSignatureFactory, DigitalSignatureType } from "../src-ts/digital-signature/digital-signature-factory";
|
|
3
|
+
import { CASRSADigitalSignatureResult } from "../index";
|
|
4
|
+
|
|
5
|
+
describe("Digital Signature", () => {
|
|
6
|
+
it("SHA 512 RSA pass", () => {
|
|
7
|
+
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA512)
|
|
8
|
+
const tohashed: string = "This is my array to encrypt";
|
|
9
|
+
const encoder = new TextEncoder();
|
|
10
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
11
|
+
const dsResult: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(2048, tohashBytes);
|
|
12
|
+
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, tohashBytes, dsResult.signature);
|
|
13
|
+
assert.equal(verify, true);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("SHA 512 RSA fails", () => {
|
|
17
|
+
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA512)
|
|
18
|
+
const tohashed: string = "This is my array to encrypt";
|
|
19
|
+
const notOriginal: string = "This is not a fun time";
|
|
20
|
+
const encoder = new TextEncoder();
|
|
21
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
22
|
+
const badBytes: Array<number> = Array.from(encoder.encode(notOriginal));
|
|
23
|
+
const dsResult: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(4096, tohashBytes);
|
|
24
|
+
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, badBytes, dsResult.signature);
|
|
25
|
+
assert.equal(verify, false);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("SHA 256 RSA pass", () => {
|
|
29
|
+
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA256)
|
|
30
|
+
const tohashed: string = "This is my array to encrypt";
|
|
31
|
+
const encoder = new TextEncoder();
|
|
32
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
33
|
+
const dsResult: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(2048, tohashBytes);
|
|
34
|
+
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, tohashBytes, dsResult.signature);
|
|
35
|
+
assert.equal(verify, true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("SHA 256 RSA fails", () => {
|
|
39
|
+
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA256)
|
|
40
|
+
const tohashed: string = "This is my array to encrypt";
|
|
41
|
+
const notOriginal: string = "This is not a fun time";
|
|
42
|
+
const encoder = new TextEncoder();
|
|
43
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
44
|
+
const badBytes: Array<number> = Array.from(encoder.encode(notOriginal));
|
|
45
|
+
const dsResult: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(4096, tohashBytes);
|
|
46
|
+
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, badBytes, dsResult.signature);
|
|
47
|
+
assert.equal(verify, false);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import { assert } from "chai";
|
|
2
|
-
import { SHAWrapper } from "../src-ts/hashers/index";
|
|
3
|
-
|
|
4
|
-
describe("SHA512 Tests", () => {
|
|
5
|
-
it("hash", () => {
|
|
6
|
-
const wrapper = new SHAWrapper();
|
|
7
|
-
const tohashed: string = "This is my array to hash";
|
|
8
|
-
const encoder = new TextEncoder();
|
|
9
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
10
|
-
const hashed = wrapper.hash_512(tohashBytes);
|
|
11
|
-
assert.notEqual(tohashBytes, hashed);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("verify pass", () => {
|
|
15
|
-
const wrapper = new SHAWrapper();
|
|
16
|
-
const tohashed: string = "This is my array to hash";
|
|
17
|
-
const encoder = new TextEncoder();
|
|
18
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
19
|
-
const hashed = wrapper.hash_512(tohashBytes);
|
|
20
|
-
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
21
|
-
const verified = wrapper.verify_512(hashed, toVerifyBytes);
|
|
22
|
-
assert.equal(true, verified);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("verify fail", () => {
|
|
26
|
-
const wrapper = new SHAWrapper();
|
|
27
|
-
const tohashed: string = "This is my array to hash";
|
|
28
|
-
const encoder = new TextEncoder();
|
|
29
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
30
|
-
const hashed = wrapper.hash_512(tohashBytes);
|
|
31
|
-
const toVerify = "This Is Not The Same";
|
|
32
|
-
const toVerifyBytes: Array<number> = Array.from(encoder.encode(toVerify));
|
|
33
|
-
const verified = wrapper.verify_512(hashed, toVerifyBytes);
|
|
34
|
-
assert.equal(false, verified);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
describe("SHA256 Tests", () => {
|
|
40
|
-
it("hash", () => {
|
|
41
|
-
const wrapper = new SHAWrapper();
|
|
42
|
-
const tohashed: string = "This is my array to hash";
|
|
43
|
-
const encoder = new TextEncoder();
|
|
44
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
45
|
-
const hashed = wrapper.hash_256(tohashBytes);
|
|
46
|
-
assert.notEqual(tohashBytes, hashed);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("verify pass", () => {
|
|
50
|
-
const wrapper = new SHAWrapper();
|
|
51
|
-
const tohashed: string = "This is my array to hash";
|
|
52
|
-
const encoder = new TextEncoder();
|
|
53
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
54
|
-
const hashed = wrapper.hash_256(tohashBytes);
|
|
55
|
-
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
56
|
-
const verified = wrapper.verify_256(hashed, toVerifyBytes);
|
|
57
|
-
assert.equal(true, verified);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("verify fail", () => {
|
|
61
|
-
const wrapper = new SHAWrapper();
|
|
62
|
-
const tohashed: string = "This is my array to hash";
|
|
63
|
-
const encoder = new TextEncoder();
|
|
64
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
65
|
-
const hashed = wrapper.hash_256(tohashBytes);
|
|
66
|
-
const toVerify = "This Is Not The Same";
|
|
67
|
-
const toVerifyBytes: Array<number> = Array.from(encoder.encode(toVerify));
|
|
68
|
-
const verified = wrapper.verify_256(hashed, toVerifyBytes);
|
|
69
|
-
assert.equal(false, verified);
|
|
70
|
-
});
|
|
1
|
+
import { assert } from "chai";
|
|
2
|
+
import { SHAWrapper } from "../src-ts/hashers/index";
|
|
3
|
+
|
|
4
|
+
describe("SHA512 Tests", () => {
|
|
5
|
+
it("hash", () => {
|
|
6
|
+
const wrapper = new SHAWrapper();
|
|
7
|
+
const tohashed: string = "This is my array to hash";
|
|
8
|
+
const encoder = new TextEncoder();
|
|
9
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
10
|
+
const hashed = wrapper.hash_512(tohashBytes);
|
|
11
|
+
assert.notEqual(tohashBytes, hashed);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("verify pass", () => {
|
|
15
|
+
const wrapper = new SHAWrapper();
|
|
16
|
+
const tohashed: string = "This is my array to hash";
|
|
17
|
+
const encoder = new TextEncoder();
|
|
18
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
19
|
+
const hashed = wrapper.hash_512(tohashBytes);
|
|
20
|
+
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
21
|
+
const verified = wrapper.verify_512(hashed, toVerifyBytes);
|
|
22
|
+
assert.equal(true, verified);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("verify fail", () => {
|
|
26
|
+
const wrapper = new SHAWrapper();
|
|
27
|
+
const tohashed: string = "This is my array to hash";
|
|
28
|
+
const encoder = new TextEncoder();
|
|
29
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
30
|
+
const hashed = wrapper.hash_512(tohashBytes);
|
|
31
|
+
const toVerify = "This Is Not The Same";
|
|
32
|
+
const toVerifyBytes: Array<number> = Array.from(encoder.encode(toVerify));
|
|
33
|
+
const verified = wrapper.verify_512(hashed, toVerifyBytes);
|
|
34
|
+
assert.equal(false, verified);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
describe("SHA256 Tests", () => {
|
|
40
|
+
it("hash", () => {
|
|
41
|
+
const wrapper = new SHAWrapper();
|
|
42
|
+
const tohashed: string = "This is my array to hash";
|
|
43
|
+
const encoder = new TextEncoder();
|
|
44
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
45
|
+
const hashed = wrapper.hash_256(tohashBytes);
|
|
46
|
+
assert.notEqual(tohashBytes, hashed);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("verify pass", () => {
|
|
50
|
+
const wrapper = new SHAWrapper();
|
|
51
|
+
const tohashed: string = "This is my array to hash";
|
|
52
|
+
const encoder = new TextEncoder();
|
|
53
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
54
|
+
const hashed = wrapper.hash_256(tohashBytes);
|
|
55
|
+
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
56
|
+
const verified = wrapper.verify_256(hashed, toVerifyBytes);
|
|
57
|
+
assert.equal(true, verified);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("verify fail", () => {
|
|
61
|
+
const wrapper = new SHAWrapper();
|
|
62
|
+
const tohashed: string = "This is my array to hash";
|
|
63
|
+
const encoder = new TextEncoder();
|
|
64
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
65
|
+
const hashed = wrapper.hash_256(tohashBytes);
|
|
66
|
+
const toVerify = "This Is Not The Same";
|
|
67
|
+
const toVerifyBytes: Array<number> = Array.from(encoder.encode(toVerify));
|
|
68
|
+
const verified = wrapper.verify_256(hashed, toVerifyBytes);
|
|
69
|
+
assert.equal(false, verified);
|
|
70
|
+
});
|
|
71
71
|
});
|
package/test-ts/helpers/array.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export const areEqual = (a: any, b: any) => {
|
|
2
|
-
if (a === b) return true;
|
|
3
|
-
if (a == null || b == null) return false;
|
|
4
|
-
if (a.length !== b.length) return false;
|
|
5
|
-
|
|
6
|
-
for (var i = 0; i < a.length; ++i) {
|
|
7
|
-
if (a[i] !== b[i]) return false;
|
|
8
|
-
}
|
|
9
|
-
return true;
|
|
1
|
+
export const areEqual = (a: any, b: any) => {
|
|
2
|
+
if (a === b) return true;
|
|
3
|
+
if (a == null || b == null) return false;
|
|
4
|
+
if (a.length !== b.length) return false;
|
|
5
|
+
|
|
6
|
+
for (var i = 0; i < a.length; ++i) {
|
|
7
|
+
if (a[i] !== b[i]) return false;
|
|
8
|
+
}
|
|
9
|
+
return true;
|
|
10
10
|
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { assert } from "chai";
|
|
2
|
+
import {
|
|
3
|
+
AESRSAHybridInitializer,
|
|
4
|
+
AesRsaHybridEncryptResult,
|
|
5
|
+
HybridEncryptionWrapper,
|
|
6
|
+
} from "../src-ts/hybrid/index";
|
|
7
|
+
import { areEqual } from "./helpers/array";
|
|
8
|
+
|
|
9
|
+
describe("Hybrid Encryption Tests", () => {
|
|
10
|
+
it("RSA 4096 AES 128 encrypt and decrypt equals", () => {
|
|
11
|
+
const hybridWrapper = new HybridEncryptionWrapper();
|
|
12
|
+
let initalizer = new AESRSAHybridInitializer(128, 4096);
|
|
13
|
+
const tohashed: string = "This is my encrypt text for rsa hybrid";
|
|
14
|
+
const encoder = new TextEncoder();
|
|
15
|
+
const toEncrypt: Array<number> = Array.from(encoder.encode(tohashed));
|
|
16
|
+
let result: AesRsaHybridEncryptResult = hybridWrapper.encrypt(toEncrypt, initalizer);
|
|
17
|
+
let plaintext: Array<number> = hybridWrapper.decrypt(initalizer.rsaKeyPair.privateKey, result);
|
|
18
|
+
let result2 = areEqual(toEncrypt, plaintext);
|
|
19
|
+
assert.isTrue(result2);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("RSA 2048 AES 256 encrypt and decrypt equals", () => {
|
|
23
|
+
const hybridWrapper = new HybridEncryptionWrapper();
|
|
24
|
+
let initalizer = new AESRSAHybridInitializer(256, 2048);
|
|
25
|
+
const tohashed: string = "This is my encrypt text for rsa hybrid";
|
|
26
|
+
const encoder = new TextEncoder();
|
|
27
|
+
const toEncrypt: Array<number> = Array.from(encoder.encode(tohashed));
|
|
28
|
+
let result: AesRsaHybridEncryptResult = hybridWrapper.encrypt(toEncrypt, initalizer);
|
|
29
|
+
let plaintext: Array<number> = hybridWrapper.decrypt(initalizer.rsaKeyPair.privateKey, result);
|
|
30
|
+
let result2 = areEqual(toEncrypt, plaintext);
|
|
31
|
+
assert.isTrue(result2);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -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
|
+
});
|