cas-typescript-sdk 1.0.21 → 1.0.23
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/Cargo.toml +1 -0
- package/README.md +7 -5
- package/index.d.ts +6 -0
- package/index.node +0 -0
- package/lib/asymmetric/RSAWrapper.d.ts +31 -1
- package/lib/asymmetric/RSAWrapper.js +33 -3
- package/lib/digital-signature/digital-siganture-sha-512.d.ts +25 -0
- package/lib/digital-signature/digital-siganture-sha-512.js +25 -0
- package/lib/digital-signature/digital-signature-factory.d.ts +5 -0
- package/lib/digital-signature/digital-signature-factory.js +5 -0
- package/lib/digital-signature/digital-signaturte-sha-256.d.ts +25 -0
- package/lib/digital-signature/digital-signaturte-sha-256.js +25 -0
- package/lib/hashers/hasher-factory.d.ts +5 -0
- package/lib/hashers/hasher-factory.js +5 -0
- package/lib/hashers/sha-wrapper.d.ts +22 -0
- package/lib/hashers/sha-wrapper.js +22 -0
- package/lib/hybrid/hybrid-encryption-wrapper.d.ts +12 -0
- package/lib/hybrid/hybrid-encryption-wrapper.js +12 -0
- package/lib/hybrid/types/aes-rsa-hybrid-initializer.d.ts +5 -0
- package/lib/hybrid/types/aes-rsa-hybrid-initializer.js +5 -0
- package/lib/key_exchange/x25519.d.ts +13 -1
- package/lib/key_exchange/x25519.js +12 -0
- package/lib/password-hashers/argon2-wrapper.d.ts +24 -0
- package/lib/password-hashers/argon2-wrapper.js +37 -0
- package/lib/password-hashers/bcrypt-wrapper.d.ts +24 -0
- package/lib/password-hashers/bcrypt-wrapper.js +34 -0
- package/lib/password-hashers/password-hasher-base.d.ts +2 -0
- package/lib/password-hashers/password-hasher-factory.d.ts +5 -0
- package/lib/password-hashers/password-hasher-factory.js +5 -0
- package/lib/password-hashers/scrypt-wrapper.d.ts +24 -0
- package/lib/password-hashers/scrypt-wrapper.js +34 -0
- package/lib/sponges/ascon-wrapper.d.ts +22 -0
- package/lib/sponges/ascon-wrapper.js +22 -0
- package/lib/symmetric/aes-wrapper.d.ts +42 -12
- package/lib/symmetric/aes-wrapper.js +42 -12
- package/package.json +1 -1
- package/src/password_hashers/argon2.rs +40 -1
- package/src/password_hashers/bcrypt.rs +39 -0
- package/src/password_hashers/scrypt.rs +39 -0
- package/src-ts/asymmetric/RSAWrapper.ts +36 -3
- package/src-ts/digital-signature/digital-siganture-sha-512.ts +26 -1
- package/src-ts/digital-signature/digital-signature-factory.ts +6 -0
- package/src-ts/digital-signature/digital-signaturte-sha-256.ts +25 -0
- package/src-ts/hashers/hasher-factory.ts +5 -0
- package/src-ts/hashers/sha-wrapper.ts +22 -0
- package/src-ts/hybrid/hybrid-encryption-wrapper.ts +12 -0
- package/src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts +5 -0
- package/src-ts/key_exchange/x25519.ts +13 -1
- package/src-ts/password-hashers/argon2-wrapper.ts +46 -4
- package/src-ts/password-hashers/bcrypt-wrapper.ts +40 -1
- package/src-ts/password-hashers/password-hasher-base.ts +2 -0
- package/src-ts/password-hashers/password-hasher-factory.ts +5 -0
- package/src-ts/password-hashers/scrypt-wrapper.ts +54 -15
- package/src-ts/sponges/ascon-wrapper.ts +22 -0
- package/src-ts/symmetric/aes-wrapper.ts +43 -12
- package/test-ts/password-hasher.test.spec.ts +53 -3
- package/lib/helpers/nonce-generator.d.ts +0 -3
- package/lib/helpers/nonce-generator.js +0 -34
- package/src-ts/helpers/nonce-generator.ts +0 -9
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
2
2
|
export declare class BCryptWrapper implements IPasswordHasherBase {
|
|
3
|
+
/**
|
|
4
|
+
* Verifies a password with BCrypt on the threadpool.
|
|
5
|
+
* @param hashedPassword
|
|
6
|
+
* @param passwordToCheck
|
|
7
|
+
* @returns boolean
|
|
8
|
+
*/
|
|
9
|
+
verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Hashes a password with BCrypt on the threadpool.
|
|
12
|
+
* @param password
|
|
13
|
+
* @returns string
|
|
14
|
+
*/
|
|
15
|
+
hashPasswordThreadPool(password: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Hashes a password with BCrypt
|
|
18
|
+
* @param password
|
|
19
|
+
* @returns string
|
|
20
|
+
*/
|
|
3
21
|
hashPassword(password: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Verifies that a password is the same as the hashed password with BCrypt.
|
|
24
|
+
* @param hashedPassword
|
|
25
|
+
* @param passwordToVerify
|
|
26
|
+
* @returns boolean
|
|
27
|
+
*/
|
|
4
28
|
verify(hashedPassword: string, passwordToVerify: string): boolean;
|
|
5
29
|
}
|
|
@@ -3,12 +3,46 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BCryptWrapper = void 0;
|
|
4
4
|
const index_1 = require("./../../index");
|
|
5
5
|
class BCryptWrapper {
|
|
6
|
+
/**
|
|
7
|
+
* Verifies a password with BCrypt on the threadpool.
|
|
8
|
+
* @param hashedPassword
|
|
9
|
+
* @param passwordToCheck
|
|
10
|
+
* @returns boolean
|
|
11
|
+
*/
|
|
12
|
+
verifyThreadPool(hashedPassword, passwordToCheck) {
|
|
13
|
+
if (!hashedPassword || !passwordToCheck) {
|
|
14
|
+
throw new Error("You must provide a hashed password and a plaintext password to verify with Argon2");
|
|
15
|
+
}
|
|
16
|
+
return (0, index_1.bcryptVerifyThreadpool)(hashedPassword, passwordToCheck);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Hashes a password with BCrypt on the threadpool.
|
|
20
|
+
* @param password
|
|
21
|
+
* @returns string
|
|
22
|
+
*/
|
|
23
|
+
hashPasswordThreadPool(password) {
|
|
24
|
+
if (!password) {
|
|
25
|
+
throw new Error("You must provide a password to hash with Argon2");
|
|
26
|
+
}
|
|
27
|
+
return (0, index_1.bcryptHashThreadpool)(password);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Hashes a password with BCrypt
|
|
31
|
+
* @param password
|
|
32
|
+
* @returns string
|
|
33
|
+
*/
|
|
6
34
|
hashPassword(password) {
|
|
7
35
|
if (!password) {
|
|
8
36
|
throw new Error("You must provide a password to hash with Argon2");
|
|
9
37
|
}
|
|
10
38
|
return (0, index_1.bcryptHash)(password);
|
|
11
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Verifies that a password is the same as the hashed password with BCrypt.
|
|
42
|
+
* @param hashedPassword
|
|
43
|
+
* @param passwordToVerify
|
|
44
|
+
* @returns boolean
|
|
45
|
+
*/
|
|
12
46
|
verify(hashedPassword, passwordToVerify) {
|
|
13
47
|
if (!hashedPassword || !passwordToVerify) {
|
|
14
48
|
throw new Error("You must provide a hashed password and a plaintext password to verify with Argon2");
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export interface IPasswordHasherBase {
|
|
2
2
|
hashPassword(password: string): string;
|
|
3
3
|
verify(hashedPassword: string, passwordToVerify: string): boolean;
|
|
4
|
+
hashPasswordThreadPool(password: string): string;
|
|
5
|
+
verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean;
|
|
4
6
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { PasswordHasherType } from "./password-hasher-type";
|
|
2
2
|
export declare class PasswordHasherFactory {
|
|
3
|
+
/**
|
|
4
|
+
* Returns the appropriate hasher type based upon the type passed in.
|
|
5
|
+
* @param type
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
3
8
|
static getHasher(type: PasswordHasherType): any;
|
|
4
9
|
}
|
|
@@ -6,6 +6,11 @@ const bcrypt_wrapper_1 = require("./bcrypt-wrapper");
|
|
|
6
6
|
const password_hasher_type_1 = require("./password-hasher-type");
|
|
7
7
|
const scrypt_wrapper_1 = require("./scrypt-wrapper");
|
|
8
8
|
class PasswordHasherFactory {
|
|
9
|
+
/**
|
|
10
|
+
* Returns the appropriate hasher type based upon the type passed in.
|
|
11
|
+
* @param type
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
9
14
|
static getHasher(type) {
|
|
10
15
|
// Argon2 by default
|
|
11
16
|
let hasher = new argon2_wrapper_1.Argon2Wrapper();
|
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
2
2
|
export declare class ScryptWrapper implements IPasswordHasherBase {
|
|
3
|
+
/**
|
|
4
|
+
* Verifies a password with SCrypt on the threadpool.
|
|
5
|
+
* @param hashedPassword
|
|
6
|
+
* @param passwordToCheck
|
|
7
|
+
* @returns boolean
|
|
8
|
+
*/
|
|
9
|
+
verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Hashes a password with SCrypt on the threadpool.
|
|
12
|
+
* @param password
|
|
13
|
+
* @returns string
|
|
14
|
+
*/
|
|
15
|
+
hashPasswordThreadPool(password: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Hashes a password with SCrypt
|
|
18
|
+
* @param password
|
|
19
|
+
* @returns string
|
|
20
|
+
*/
|
|
3
21
|
hashPassword(password: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Verifies that a password is the same as the hashed password with SCrypt.
|
|
24
|
+
* @param hashedPassword
|
|
25
|
+
* @param passwordToVerify
|
|
26
|
+
* @returns boolean
|
|
27
|
+
*/
|
|
4
28
|
verify(hashedPassword: string, passwordToVerify: string): boolean;
|
|
5
29
|
}
|
|
@@ -3,12 +3,46 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ScryptWrapper = void 0;
|
|
4
4
|
const index_1 = require("../../index");
|
|
5
5
|
class ScryptWrapper {
|
|
6
|
+
/**
|
|
7
|
+
* Verifies a password with SCrypt on the threadpool.
|
|
8
|
+
* @param hashedPassword
|
|
9
|
+
* @param passwordToCheck
|
|
10
|
+
* @returns boolean
|
|
11
|
+
*/
|
|
12
|
+
verifyThreadPool(hashedPassword, passwordToCheck) {
|
|
13
|
+
if (!hashedPassword || !passwordToCheck) {
|
|
14
|
+
throw new Error("You must provide a hashed password and a plaintext password to verify with Scrypt");
|
|
15
|
+
}
|
|
16
|
+
return (0, index_1.scryptVerifyThreadpool)(hashedPassword, passwordToCheck);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Hashes a password with SCrypt on the threadpool.
|
|
20
|
+
* @param password
|
|
21
|
+
* @returns string
|
|
22
|
+
*/
|
|
23
|
+
hashPasswordThreadPool(password) {
|
|
24
|
+
if (!password) {
|
|
25
|
+
throw new Error("You must provide a password to hash with Scrypt");
|
|
26
|
+
}
|
|
27
|
+
return (0, index_1.scryptHashThreadpool)(password);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Hashes a password with SCrypt
|
|
31
|
+
* @param password
|
|
32
|
+
* @returns string
|
|
33
|
+
*/
|
|
6
34
|
hashPassword(password) {
|
|
7
35
|
if (!password) {
|
|
8
36
|
throw new Error("You must provide a password to hash with Scrypt");
|
|
9
37
|
}
|
|
10
38
|
return (0, index_1.scryptHash)(password);
|
|
11
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Verifies that a password is the same as the hashed password with SCrypt.
|
|
42
|
+
* @param hashedPassword
|
|
43
|
+
* @param passwordToVerify
|
|
44
|
+
* @returns boolean
|
|
45
|
+
*/
|
|
12
46
|
verify(hashedPassword, passwordToVerify) {
|
|
13
47
|
if (!hashedPassword || !passwordToVerify) {
|
|
14
48
|
throw new Error("You must provide a hashed password and a plaintext password to verify with Scrypt");
|
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
export declare class AsconWrapper {
|
|
2
|
+
/**
|
|
3
|
+
* Generates an Ascon 128 key
|
|
4
|
+
* @returns Array<number>
|
|
5
|
+
*/
|
|
2
6
|
ascon128Key(): Array<number>;
|
|
7
|
+
/**
|
|
8
|
+
* Generates and Ascon 128 nonce.
|
|
9
|
+
* @returns Array<number>
|
|
10
|
+
*/
|
|
3
11
|
ascon128Nonce(): Array<number>;
|
|
12
|
+
/**
|
|
13
|
+
* Encrypts with Ascon 128 using the key and nonce generated from ascon128Key() and ascon128Nonce() respectively.
|
|
14
|
+
* @param key
|
|
15
|
+
* @param nonce
|
|
16
|
+
* @param plaintext
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
4
19
|
ascon128Encrypt(key: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>;
|
|
20
|
+
/**
|
|
21
|
+
* Decrypts with Ascon 128 using the key and nonce generated from ascon128Key() and ascon128Nonce() respectively.
|
|
22
|
+
* @param key
|
|
23
|
+
* @param nonce
|
|
24
|
+
* @param ciphertext
|
|
25
|
+
* @returns Array<number>
|
|
26
|
+
*/
|
|
5
27
|
ascon128Decrypt(key: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>;
|
|
6
28
|
}
|
|
@@ -3,12 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AsconWrapper = void 0;
|
|
4
4
|
const index_1 = require("../../index");
|
|
5
5
|
class AsconWrapper {
|
|
6
|
+
/**
|
|
7
|
+
* Generates an Ascon 128 key
|
|
8
|
+
* @returns Array<number>
|
|
9
|
+
*/
|
|
6
10
|
ascon128Key() {
|
|
7
11
|
return (0, index_1.ascon128KeyGenerate)();
|
|
8
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Generates and Ascon 128 nonce.
|
|
15
|
+
* @returns Array<number>
|
|
16
|
+
*/
|
|
9
17
|
ascon128Nonce() {
|
|
10
18
|
return (0, index_1.ascon128NonceGenerate)();
|
|
11
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Encrypts with Ascon 128 using the key and nonce generated from ascon128Key() and ascon128Nonce() respectively.
|
|
22
|
+
* @param key
|
|
23
|
+
* @param nonce
|
|
24
|
+
* @param plaintext
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
12
27
|
ascon128Encrypt(key, nonce, plaintext) {
|
|
13
28
|
if (!key || key.length === 0) {
|
|
14
29
|
throw new Error("Key is required");
|
|
@@ -21,6 +36,13 @@ class AsconWrapper {
|
|
|
21
36
|
}
|
|
22
37
|
return (0, index_1.ascon128Encrypt)(key, nonce, plaintext);
|
|
23
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Decrypts with Ascon 128 using the key and nonce generated from ascon128Key() and ascon128Nonce() respectively.
|
|
41
|
+
* @param key
|
|
42
|
+
* @param nonce
|
|
43
|
+
* @param ciphertext
|
|
44
|
+
* @returns Array<number>
|
|
45
|
+
*/
|
|
24
46
|
ascon128Decrypt(key, nonce, ciphertext) {
|
|
25
47
|
if (!key || key.length === 0) {
|
|
26
48
|
throw new Error("Key is required");
|
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
import { AesKeyFromX25519SharedSecret } from "../../index";
|
|
2
|
-
/**
|
|
3
|
-
* @description A wrapper class that contains methods to construct keys, nonces, and methods to encrypt and decrypt with AES-128-GCM and AES-256-GCM
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* const nonce = aesWrapper.generateAESNonce();
|
|
8
|
-
const key = aesWrapper.aes128Key();
|
|
9
|
-
const textEncoder = new TextEncoder();
|
|
10
|
-
const array = Array.from(textEncoder.encode("Hello World"));
|
|
11
|
-
const encrypted = aesWrapper.aes128Encrypt(key, nonce, array);
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
2
|
export declare class AESWrapper {
|
|
15
3
|
/**
|
|
16
4
|
* @description Generates a 128 bit AES key
|
|
@@ -22,11 +10,53 @@ export declare class AESWrapper {
|
|
|
22
10
|
* @returns returns a 256 bit AES key
|
|
23
11
|
*/
|
|
24
12
|
aes256Key(): Array<number>;
|
|
13
|
+
/**
|
|
14
|
+
* Generates an 96 bit AES nonce
|
|
15
|
+
* @returns Array<number>
|
|
16
|
+
*/
|
|
25
17
|
generateAESNonce(): Array<number>;
|
|
18
|
+
/**
|
|
19
|
+
* Encrypts with AES 128.
|
|
20
|
+
* @param aesKey
|
|
21
|
+
* @param nonce
|
|
22
|
+
* @param plaintext
|
|
23
|
+
* @returns Array<number>
|
|
24
|
+
*/
|
|
26
25
|
aes128Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>;
|
|
26
|
+
/**
|
|
27
|
+
* Decrypts with AES 128
|
|
28
|
+
* @param aesKey
|
|
29
|
+
* @param nonce
|
|
30
|
+
* @param ciphertext
|
|
31
|
+
* @returns Array<number>
|
|
32
|
+
*/
|
|
27
33
|
aes128Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>;
|
|
34
|
+
/**
|
|
35
|
+
* Encrypts with AES-256
|
|
36
|
+
* @param aesKey
|
|
37
|
+
* @param nonce
|
|
38
|
+
* @param plaintext
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
28
41
|
aes256Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>;
|
|
42
|
+
/**
|
|
43
|
+
* Decrypts with AES 256
|
|
44
|
+
* @param aesKey
|
|
45
|
+
* @param nonce
|
|
46
|
+
* @param ciphertext
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
29
49
|
aes256Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>;
|
|
50
|
+
/**
|
|
51
|
+
* Derives an AES-256 key from a X25519 Diffie Hellman shared secret.
|
|
52
|
+
* @param shared_secret
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
30
55
|
aes256KeyNonceX25519DiffieHellman(shared_secret: Array<number>): AesKeyFromX25519SharedSecret;
|
|
56
|
+
/**
|
|
57
|
+
* Derives an AES-128 key from a X25519 Diffie Hellman shared secret.
|
|
58
|
+
* @param shared_secret
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
31
61
|
aes128KeyNonceX25519DiffieHellman(shared_secret: Array<number>): AesKeyFromX25519SharedSecret;
|
|
32
62
|
}
|
|
@@ -2,18 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AESWrapper = void 0;
|
|
4
4
|
const index_1 = require("../../index");
|
|
5
|
-
/**
|
|
6
|
-
* @description A wrapper class that contains methods to construct keys, nonces, and methods to encrypt and decrypt with AES-128-GCM and AES-256-GCM
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* const nonce = aesWrapper.generateAESNonce();
|
|
11
|
-
const key = aesWrapper.aes128Key();
|
|
12
|
-
const textEncoder = new TextEncoder();
|
|
13
|
-
const array = Array.from(textEncoder.encode("Hello World"));
|
|
14
|
-
const encrypted = aesWrapper.aes128Encrypt(key, nonce, array);
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
5
|
class AESWrapper {
|
|
18
6
|
/**
|
|
19
7
|
* @description Generates a 128 bit AES key
|
|
@@ -29,24 +17,66 @@ class AESWrapper {
|
|
|
29
17
|
aes256Key() {
|
|
30
18
|
return (0, index_1.aes256Key)();
|
|
31
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Generates an 96 bit AES nonce
|
|
22
|
+
* @returns Array<number>
|
|
23
|
+
*/
|
|
32
24
|
generateAESNonce() {
|
|
33
25
|
return (0, index_1.aesNonce)();
|
|
34
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Encrypts with AES 128.
|
|
29
|
+
* @param aesKey
|
|
30
|
+
* @param nonce
|
|
31
|
+
* @param plaintext
|
|
32
|
+
* @returns Array<number>
|
|
33
|
+
*/
|
|
35
34
|
aes128Encrypt(aesKey, nonce, plaintext) {
|
|
36
35
|
return (0, index_1.aes128Encrypt)(aesKey, nonce, plaintext);
|
|
37
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Decrypts with AES 128
|
|
39
|
+
* @param aesKey
|
|
40
|
+
* @param nonce
|
|
41
|
+
* @param ciphertext
|
|
42
|
+
* @returns Array<number>
|
|
43
|
+
*/
|
|
38
44
|
aes128Decrypt(aesKey, nonce, ciphertext) {
|
|
39
45
|
return (0, index_1.aes128Decrypt)(aesKey, nonce, ciphertext);
|
|
40
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Encrypts with AES-256
|
|
49
|
+
* @param aesKey
|
|
50
|
+
* @param nonce
|
|
51
|
+
* @param plaintext
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
41
54
|
aes256Encrypt(aesKey, nonce, plaintext) {
|
|
42
55
|
return (0, index_1.aes256Encrypt)(aesKey, nonce, plaintext);
|
|
43
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Decrypts with AES 256
|
|
59
|
+
* @param aesKey
|
|
60
|
+
* @param nonce
|
|
61
|
+
* @param ciphertext
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
44
64
|
aes256Decrypt(aesKey, nonce, ciphertext) {
|
|
45
65
|
return (0, index_1.aes256Decrypt)(aesKey, nonce, ciphertext);
|
|
46
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Derives an AES-256 key from a X25519 Diffie Hellman shared secret.
|
|
69
|
+
* @param shared_secret
|
|
70
|
+
* @returns
|
|
71
|
+
*/
|
|
47
72
|
aes256KeyNonceX25519DiffieHellman(shared_secret) {
|
|
48
73
|
return (0, index_1.aes256KeyFromX25519SharedSecret)(shared_secret);
|
|
49
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Derives an AES-128 key from a X25519 Diffie Hellman shared secret.
|
|
77
|
+
* @param shared_secret
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
50
80
|
aes128KeyNonceX25519DiffieHellman(shared_secret) {
|
|
51
81
|
return (0, index_1.aes128KeyFromX25519SharedSecret)(shared_secret);
|
|
52
82
|
}
|
package/package.json
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
use std::net::ToSocketAddrs;
|
|
2
1
|
|
|
3
2
|
use napi_derive::napi;
|
|
4
3
|
|
|
@@ -7,6 +6,8 @@ use argon2::{
|
|
|
7
6
|
Argon2, PasswordHash, PasswordHasher, PasswordVerifier,
|
|
8
7
|
};
|
|
9
8
|
|
|
9
|
+
use crate::symmetric::aes::CASAES128;
|
|
10
|
+
|
|
10
11
|
use super::cas_password_hasher::CASPasswordHasher;
|
|
11
12
|
|
|
12
13
|
pub struct CASArgon;
|
|
@@ -35,11 +36,49 @@ pub fn argon2_hash(password: String) -> String {
|
|
|
35
36
|
return <CASArgon as CASPasswordHasher>::hash_password(password);
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
#[napi]
|
|
40
|
+
pub fn argon2_hash_thread_pool(password: String) -> String {
|
|
41
|
+
let (sender, receiver) = std::sync::mpsc::channel();
|
|
42
|
+
rayon::spawn(move || {
|
|
43
|
+
let hash_result = <CASArgon as CASPasswordHasher>::hash_password(password);
|
|
44
|
+
sender.send(hash_result);
|
|
45
|
+
});
|
|
46
|
+
let result = receiver.recv().unwrap();
|
|
47
|
+
result
|
|
48
|
+
}
|
|
49
|
+
|
|
38
50
|
#[napi]
|
|
39
51
|
pub fn argon2_verify(hashed_password: String, password_to_verify: String) -> bool {
|
|
40
52
|
return <CASArgon as CASPasswordHasher>::verify_password(hashed_password, password_to_verify);
|
|
41
53
|
}
|
|
42
54
|
|
|
55
|
+
#[napi]
|
|
56
|
+
pub fn argon2_verify_threadpool(hashed_password: String, password_to_verify: String) -> bool {
|
|
57
|
+
let (sender, receiver) = std::sync::mpsc::channel();
|
|
58
|
+
rayon::spawn(move || {
|
|
59
|
+
let verify_result = <CASArgon as CASPasswordHasher>::verify_password(hashed_password, password_to_verify);
|
|
60
|
+
sender.send(verify_result);
|
|
61
|
+
});
|
|
62
|
+
let result = receiver.recv().unwrap();
|
|
63
|
+
result
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
#[test]
|
|
67
|
+
pub fn argon2_hash_threadpool_test() {
|
|
68
|
+
let password = "ThisIsNotMyPasswolrd".to_string();
|
|
69
|
+
let hashed = argon2_hash_thread_pool(password.clone());
|
|
70
|
+
assert_ne!(password, hashed);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
#[test]
|
|
74
|
+
pub fn argon2_verify_threadpool_test() {
|
|
75
|
+
let password = "ThisIsNotMyPasswolrd".to_string();
|
|
76
|
+
let passwordToCheck = "ThisIsNotMyPasswolrd".to_string();
|
|
77
|
+
let hashed = argon2_hash_thread_pool(password);
|
|
78
|
+
let result = argon2_verify_threadpool(hashed, passwordToCheck);
|
|
79
|
+
assert_eq!(result, true);
|
|
80
|
+
}
|
|
81
|
+
|
|
43
82
|
#[test]
|
|
44
83
|
pub fn argon2_hash_test() {
|
|
45
84
|
let password = "ThisIsNotMyPasswolrd".to_string();
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
use std::sync::mpsc;
|
|
2
|
+
|
|
1
3
|
use bcrypt::{hash, verify, DEFAULT_COST};
|
|
2
4
|
use napi_derive::napi;
|
|
3
5
|
|
|
@@ -20,11 +22,33 @@ pub fn bcrypt_hash(password_to_hash: String) -> String {
|
|
|
20
22
|
return <CASBCrypt as CASPasswordHasher>::hash_password(password_to_hash);
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
#[napi]
|
|
26
|
+
pub fn bcrypt_hash_threadpool(password_to_hash: String) -> String {
|
|
27
|
+
let (sender, receiver) = mpsc::channel();
|
|
28
|
+
rayon::spawn(move || {
|
|
29
|
+
let thread_result = <CASBCrypt as CASPasswordHasher>::hash_password(password_to_hash);
|
|
30
|
+
sender.send(thread_result);
|
|
31
|
+
});
|
|
32
|
+
let result = receiver.recv().unwrap();
|
|
33
|
+
result
|
|
34
|
+
}
|
|
35
|
+
|
|
23
36
|
#[napi]
|
|
24
37
|
pub fn bcrypt_verify(hashed_password: String, password_to_verify: String) -> bool {
|
|
25
38
|
return <CASBCrypt as CASPasswordHasher>::verify_password(hashed_password, password_to_verify);
|
|
26
39
|
}
|
|
27
40
|
|
|
41
|
+
#[napi]
|
|
42
|
+
pub fn bcrypt_verify_threadpool(password_to_hash: String, password_to_verify: String) -> bool {
|
|
43
|
+
let (sender, receiver) = mpsc::channel();
|
|
44
|
+
rayon::spawn(move || {
|
|
45
|
+
let thread_result = <CASBCrypt as CASPasswordHasher>::verify_password(password_to_hash, password_to_verify);
|
|
46
|
+
sender.send(thread_result);
|
|
47
|
+
});
|
|
48
|
+
let result = receiver.recv().unwrap();
|
|
49
|
+
result
|
|
50
|
+
}
|
|
51
|
+
|
|
28
52
|
#[test]
|
|
29
53
|
pub fn bcrypt_hash_test() {
|
|
30
54
|
let password = "ThisIsNotMyPasswolrd".to_string();
|
|
@@ -32,6 +56,13 @@ pub fn bcrypt_hash_test() {
|
|
|
32
56
|
assert_ne!(password, hashed);
|
|
33
57
|
}
|
|
34
58
|
|
|
59
|
+
#[test]
|
|
60
|
+
pub fn bcrypt_hash_threadpool_test() {
|
|
61
|
+
let password = "ThisIsNotMyPasswolrd".to_string();
|
|
62
|
+
let hashed = bcrypt_hash_threadpool(password.clone());
|
|
63
|
+
assert_ne!(password, hashed);
|
|
64
|
+
}
|
|
65
|
+
|
|
35
66
|
#[test]
|
|
36
67
|
pub fn bcrypt_verify_test() {
|
|
37
68
|
let password = "ThisIsNotMyPasswolrd".to_string();
|
|
@@ -40,6 +71,14 @@ pub fn bcrypt_verify_test() {
|
|
|
40
71
|
assert_eq!(true, verified);
|
|
41
72
|
}
|
|
42
73
|
|
|
74
|
+
#[test]
|
|
75
|
+
pub fn bcrypt_verify_threadpool_test() {
|
|
76
|
+
let password = "ThisIsNotMyPasswolrd".to_string();
|
|
77
|
+
let hashed = bcrypt_hash_threadpool(password.clone());
|
|
78
|
+
let verified = bcrypt_verify_threadpool(hashed, password);
|
|
79
|
+
assert_eq!(true, verified);
|
|
80
|
+
}
|
|
81
|
+
|
|
43
82
|
#[test]
|
|
44
83
|
pub fn bcrypt_verify_fail_test() {
|
|
45
84
|
let password = "ThisIsNotMyPasswolrd".to_string();
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
use std::sync::mpsc;
|
|
2
|
+
|
|
1
3
|
use napi_derive::napi;
|
|
2
4
|
|
|
3
5
|
use scrypt::{
|
|
@@ -36,6 +38,43 @@ pub fn scrypt_verify(hashed_password: String, password_to_verify: String) -> boo
|
|
|
36
38
|
return <CASScrypt as CASPasswordHasher>::verify_password(hashed_password, password_to_verify);
|
|
37
39
|
}
|
|
38
40
|
|
|
41
|
+
#[napi]
|
|
42
|
+
pub fn scrypt_hash_threadpool(password_to_hash: String) -> String {
|
|
43
|
+
let (sender, receiver) = mpsc::channel();
|
|
44
|
+
rayon::spawn(move || {
|
|
45
|
+
let thread_result = <CASScrypt as CASPasswordHasher>::hash_password(password_to_hash);
|
|
46
|
+
sender.send(thread_result);
|
|
47
|
+
});
|
|
48
|
+
let result = receiver.recv().unwrap();
|
|
49
|
+
result
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#[napi]
|
|
53
|
+
pub fn scrypt_verify_threadpool(hashed_password: String, password_to_verify: String) -> bool {
|
|
54
|
+
let (sender, receiver) = mpsc::channel();
|
|
55
|
+
rayon::spawn(move || {
|
|
56
|
+
let thread_result = <CASScrypt as CASPasswordHasher>::verify_password(hashed_password, password_to_verify);
|
|
57
|
+
sender.send(thread_result);
|
|
58
|
+
});
|
|
59
|
+
let result = receiver.recv().unwrap();
|
|
60
|
+
result
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#[test]
|
|
64
|
+
pub fn scrypt_hash_threadpool_test() {
|
|
65
|
+
let password = "BadPassword".to_string();
|
|
66
|
+
let hashed_password = scrypt_hash_threadpool(password.clone());
|
|
67
|
+
assert_ne!(password, hashed_password);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
#[test]
|
|
71
|
+
pub fn scrypt_verify_threadpool_test() {
|
|
72
|
+
let password = "BadPassword".to_string();
|
|
73
|
+
let hashed_password = scrypt_hash_threadpool(password.clone());
|
|
74
|
+
let verified = scrypt_verify_threadpool(hashed_password, password);
|
|
75
|
+
assert_eq!(true, verified);
|
|
76
|
+
}
|
|
77
|
+
|
|
39
78
|
#[test]
|
|
40
79
|
pub fn scrypt_hash_test() {
|
|
41
80
|
let password = "BadPassword".to_string();
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { decryptCiphertextRsa, encryptPlaintextRsa, generateRsaKeys, RsaKeyPairResult, signRsa, verifyRsa } from "../../index";
|
|
2
2
|
|
|
3
3
|
export class RSAWrapper {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generates an RSA key pair based of parameter sent in 1024, 2048, and 4096 are supported.
|
|
7
|
+
* @param keySize
|
|
8
|
+
* @returns RsaKeyPairResult
|
|
9
|
+
*/
|
|
4
10
|
public generateKeys(keySize: number): RsaKeyPairResult {
|
|
5
11
|
if (keySize !== 1024 && keySize !== 2048 && keySize !== 4096) {
|
|
6
12
|
throw new Error("You must provide an appropriate key size to generate RSA keys");
|
|
@@ -8,6 +14,13 @@ export class RSAWrapper {
|
|
|
8
14
|
return generateRsaKeys(keySize);
|
|
9
15
|
}
|
|
10
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Encrypts a plaintext byte array with a RSA public key
|
|
19
|
+
* @param publicKey
|
|
20
|
+
* @param plaintext
|
|
21
|
+
* @returns Array<number>
|
|
22
|
+
*/
|
|
23
|
+
|
|
11
24
|
public encrypt(publicKey: string, plaintext: Array<number>): Array<number> {
|
|
12
25
|
if (!publicKey) {
|
|
13
26
|
throw new Error("You must provide a public key to encrypt with RSA");
|
|
@@ -18,6 +31,13 @@ export class RSAWrapper {
|
|
|
18
31
|
return encryptPlaintextRsa(publicKey, plaintext);
|
|
19
32
|
}
|
|
20
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Decrypts a ciphertext with an RSA private key.
|
|
36
|
+
* @param privateKey
|
|
37
|
+
* @param ciphertext
|
|
38
|
+
* @returns Array<number>
|
|
39
|
+
*/
|
|
40
|
+
|
|
21
41
|
public decrypt(privateKey: string, ciphertext: Array<number>): Array<number> {
|
|
22
42
|
if (!privateKey) {
|
|
23
43
|
throw new Error("You must provide a private key to encrypt with RSA");
|
|
@@ -28,16 +48,29 @@ export class RSAWrapper {
|
|
|
28
48
|
return decryptCiphertextRsa(privateKey, ciphertext);
|
|
29
49
|
}
|
|
30
50
|
|
|
31
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Signs a byte array with an RSA private key for verification.
|
|
53
|
+
* @param privateKey
|
|
54
|
+
* @param hash
|
|
55
|
+
* @returns Array<number>
|
|
56
|
+
*/
|
|
57
|
+
public sign(privateKey: string, dataToSign: Array<number>): Array<number> {
|
|
32
58
|
if (!privateKey) {
|
|
33
59
|
throw new Error("You must provide a private key to sign with RSA");
|
|
34
60
|
}
|
|
35
|
-
if (!
|
|
61
|
+
if (!dataToSign || dataToSign.length === 0) {
|
|
36
62
|
throw new Error("You must provide an allocated hash to sign with RSA");
|
|
37
63
|
}
|
|
38
|
-
return signRsa(privateKey,
|
|
64
|
+
return signRsa(privateKey, dataToSign);
|
|
39
65
|
}
|
|
40
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Verifies signed data by the corresponding private key with an RSA public key.
|
|
69
|
+
* @param publicKey
|
|
70
|
+
* @param hash
|
|
71
|
+
* @param signature
|
|
72
|
+
* @returns boolean
|
|
73
|
+
*/
|
|
41
74
|
public verify(publicKey: string, hash: Array<number>, signature: Array<number>): boolean {
|
|
42
75
|
if (!publicKey) {
|
|
43
76
|
throw new Error("You must provide a public key to verify with RSA");
|