cas-typescript-sdk 1.0.20 → 1.0.22
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/docs/EXAMPLES.md +99 -0
- package/index.d.ts +6 -0
- package/index.node +0 -0
- package/lib/password-hashers/argon2-wrapper.d.ts +2 -0
- package/lib/password-hashers/argon2-wrapper.js +15 -0
- package/lib/password-hashers/bcrypt-wrapper.d.ts +2 -0
- package/lib/password-hashers/bcrypt-wrapper.js +12 -0
- package/lib/password-hashers/password-hasher-base.d.ts +2 -0
- package/lib/password-hashers/scrypt-wrapper.d.ts +2 -0
- package/lib/password-hashers/scrypt-wrapper.js +12 -0
- 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/password-hashers/argon2-wrapper.ts +24 -4
- package/src-ts/password-hashers/bcrypt-wrapper.ts +18 -1
- package/src-ts/password-hashers/password-hasher-base.ts +2 -0
- package/src-ts/password-hashers/scrypt-wrapper.ts +32 -15
- package/test-ts/password-hasher.test.spec.ts +53 -3
package/Cargo.toml
CHANGED
package/docs/EXAMPLES.md
CHANGED
|
@@ -11,6 +11,105 @@ const ciphertext = aesWrapper.aes128Encrypt(aesKey, aesNonce, tohashBytes);
|
|
|
11
11
|
const plaintxt = aesWrapper.aes128Decrypt(aesKey, aesNonce, ciphertext);
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
+
### Asymmetric
|
|
15
|
+
-RSA
|
|
16
|
+
```typescript
|
|
17
|
+
const rsaWrapper: RSAWrapper = new RSAWrapper();
|
|
18
|
+
const keys: RsaKeyPairResult = rsaWrapper.generateKeys(4096);
|
|
19
|
+
const tohashed: string = "This is my array to encrypt";
|
|
20
|
+
const encoder = new TextEncoder();
|
|
21
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
22
|
+
const ciphertext = rsaWrapper.encrypt(keys.publicKey, tohashBytes);
|
|
23
|
+
const plaintext = rsaWrapper.decrypt(keys.privateKey, ciphertext);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Digital Signature
|
|
28
|
+
-ED25519 SHA
|
|
29
|
+
```typescript
|
|
30
|
+
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA256)
|
|
31
|
+
const toHash: string = "This is my array to encrypt";
|
|
32
|
+
const encoder = new TextEncoder();
|
|
33
|
+
const toHashBytes: Array<number> = Array.from(encoder.encode(toHash));
|
|
34
|
+
const dsResult = shaDsWrapper.createED25519(toHashBytes);
|
|
35
|
+
const verify = shaDsWrapper.verifyED25519(dsResult.publicKey, toHashBytes, dsResult.signature);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
-RSA SHA
|
|
39
|
+
```typescript
|
|
40
|
+
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA512)
|
|
41
|
+
const tohashed: string = "This is my array to encrypt";
|
|
42
|
+
const notOriginal: string = "This is not a fun time";
|
|
43
|
+
const encoder = new TextEncoder();
|
|
44
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
45
|
+
const badBytes: Array<number> = Array.from(encoder.encode(notOriginal));
|
|
46
|
+
const dsResult: RSADigitalSignatureResult = shaDsWrapper.createRsa(4096, tohashBytes);
|
|
47
|
+
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, badBytes, dsResult.signature);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
### Hashers
|
|
52
|
+
-SHA3 512
|
|
53
|
+
```typescript
|
|
54
|
+
const wrapper = new SHAWrapper();
|
|
55
|
+
const tohashed: string = "This is my array to hash";
|
|
56
|
+
const encoder = new TextEncoder();
|
|
57
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
58
|
+
const hashed = wrapper.hash512(tohashBytes);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
-SHA3 256
|
|
62
|
+
```typescript
|
|
63
|
+
const wrapper = new SHAWrapper();
|
|
64
|
+
const tohashed: string = "This is my array to hash";
|
|
65
|
+
const encoder = new TextEncoder();
|
|
66
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
67
|
+
const hashed = wrapper.hash256(tohashBytes);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Hybrid Encryption
|
|
71
|
+
-AES/RSA Encryption
|
|
72
|
+
```typescript
|
|
73
|
+
const hybridWrapper = new HybridEncryptionWrapper();
|
|
74
|
+
let initalizer = new AESRSAHybridInitializer(128, 4096);
|
|
75
|
+
const tohashed: string = "This is my encrypt text for rsa hybrid";
|
|
76
|
+
const encoder = new TextEncoder();
|
|
77
|
+
const toEncrypt: Array<number> = Array.from(encoder.encode(tohashed));
|
|
78
|
+
let result: AesRsaHybridEncryptResult = hybridWrapper.encrypt(toEncrypt, initalizer);
|
|
79
|
+
let plaintext: Array<number> = hybridWrapper.decrypt(initalizer.rsaKeyPair.privateKey, result);
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Key Exchange
|
|
83
|
+
-X25519
|
|
84
|
+
```typescript
|
|
85
|
+
const wrapper = new X25519Wrapper();
|
|
86
|
+
const alice = wrapper.generateSecretAndPublicKey();
|
|
87
|
+
const bob = wrapper.generateSecretAndPublicKey();
|
|
88
|
+
|
|
89
|
+
const alice_shared_secret = wrapper.generateSharedSecret(
|
|
90
|
+
alice.secretKey,
|
|
91
|
+
bob.publicKey,
|
|
92
|
+
);
|
|
93
|
+
const bob_shared_secret = wrapper.generateSharedSecret(
|
|
94
|
+
bob.secretKey,
|
|
95
|
+
alice.publicKey,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
var result = areEqual(alice_shared_secret, bob_shared_secret);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Sponges
|
|
102
|
+
-Ascon 128
|
|
103
|
+
```typescript
|
|
104
|
+
const wrapper: AsconWrapper = new AsconWrapper();
|
|
105
|
+
const key: Array<number> = wrapper.ascon128Key();
|
|
106
|
+
const nonce: Array<number> = wrapper.ascon128Nonce();
|
|
107
|
+
const tohashed: string = "This is my array to encrypt";
|
|
108
|
+
const encoder = new TextEncoder();
|
|
109
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
110
|
+
const ciphertext = wrapper.ascon128Encrypt(key, nonce, tohashBytes);
|
|
111
|
+
const plaintext = wrapper.ascon128Decrypt(key, nonce, ciphertext);
|
|
112
|
+
```
|
|
14
113
|
|
|
15
114
|
### Passwords
|
|
16
115
|
- BCrypt
|
package/index.d.ts
CHANGED
|
@@ -4,11 +4,17 @@
|
|
|
4
4
|
/* auto-generated by NAPI-RS */
|
|
5
5
|
|
|
6
6
|
export function argon2Hash(password: string): string
|
|
7
|
+
export function argon2HashThreadPool(password: string): string
|
|
7
8
|
export function argon2Verify(hashedPassword: string, passwordToVerify: string): boolean
|
|
9
|
+
export function argon2VerifyThreadpool(hashedPassword: string, passwordToVerify: string): boolean
|
|
8
10
|
export function bcryptHash(passwordToHash: string): string
|
|
11
|
+
export function bcryptHashThreadpool(passwordToHash: string): string
|
|
9
12
|
export function bcryptVerify(hashedPassword: string, passwordToVerify: string): boolean
|
|
13
|
+
export function bcryptVerifyThreadpool(passwordToHash: string, passwordToVerify: string): boolean
|
|
10
14
|
export function scryptHash(passwordToHash: string): string
|
|
11
15
|
export function scryptVerify(hashedPassword: string, passwordToVerify: string): boolean
|
|
16
|
+
export function scryptHashThreadpool(passwordToHash: string): string
|
|
17
|
+
export function scryptVerifyThreadpool(hashedPassword: string, passwordToVerify: string): boolean
|
|
12
18
|
export function sha512(dataToHash: Array<number>): Array<number>
|
|
13
19
|
export function sha512Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
14
20
|
export function sha256(dataToHash: Array<number>): Array<number>
|
package/index.node
CHANGED
|
Binary file
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
2
2
|
export declare class Argon2Wrapper implements IPasswordHasherBase {
|
|
3
|
+
verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean;
|
|
4
|
+
hashPasswordThreadPool(password: string): string;
|
|
3
5
|
hashPassword(password: string): string;
|
|
4
6
|
verify(hashedPassword: string, passwordToVerify: string): boolean;
|
|
5
7
|
}
|
|
@@ -3,6 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Argon2Wrapper = void 0;
|
|
4
4
|
const index_1 = require("./../../index");
|
|
5
5
|
class Argon2Wrapper {
|
|
6
|
+
verifyThreadPool(hashedPassword, passwordToCheck) {
|
|
7
|
+
if (!hashedPassword) {
|
|
8
|
+
throw new Error("You must provide a password to verify with Argon2");
|
|
9
|
+
}
|
|
10
|
+
if (!passwordToCheck) {
|
|
11
|
+
throw new Error("You must provide a password to check to verify with Argon2");
|
|
12
|
+
}
|
|
13
|
+
return (0, index_1.argon2VerifyThreadpool)(hashedPassword, passwordToCheck);
|
|
14
|
+
}
|
|
15
|
+
hashPasswordThreadPool(password) {
|
|
16
|
+
if (!password) {
|
|
17
|
+
throw new Error("You must provide a password to hash with Argon2");
|
|
18
|
+
}
|
|
19
|
+
return (0, index_1.argon2HashThreadPool)(password);
|
|
20
|
+
}
|
|
6
21
|
hashPassword(password) {
|
|
7
22
|
if (!password) {
|
|
8
23
|
throw new Error("You must provide a password to hash with Argon2");
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
2
2
|
export declare class BCryptWrapper implements IPasswordHasherBase {
|
|
3
|
+
verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean;
|
|
4
|
+
hashPasswordThreadPool(password: string): string;
|
|
3
5
|
hashPassword(password: string): string;
|
|
4
6
|
verify(hashedPassword: string, passwordToVerify: string): boolean;
|
|
5
7
|
}
|
|
@@ -3,6 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BCryptWrapper = void 0;
|
|
4
4
|
const index_1 = require("./../../index");
|
|
5
5
|
class BCryptWrapper {
|
|
6
|
+
verifyThreadPool(hashedPassword, passwordToCheck) {
|
|
7
|
+
if (!hashedPassword || !passwordToCheck) {
|
|
8
|
+
throw new Error("You must provide a hashed password and a plaintext password to verify with Argon2");
|
|
9
|
+
}
|
|
10
|
+
return (0, index_1.bcryptVerifyThreadpool)(hashedPassword, passwordToCheck);
|
|
11
|
+
}
|
|
12
|
+
hashPasswordThreadPool(password) {
|
|
13
|
+
if (!password) {
|
|
14
|
+
throw new Error("You must provide a password to hash with Argon2");
|
|
15
|
+
}
|
|
16
|
+
return (0, index_1.bcryptHashThreadpool)(password);
|
|
17
|
+
}
|
|
6
18
|
hashPassword(password) {
|
|
7
19
|
if (!password) {
|
|
8
20
|
throw new Error("You must provide a password to hash 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,5 +1,7 @@
|
|
|
1
1
|
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
2
2
|
export declare class ScryptWrapper implements IPasswordHasherBase {
|
|
3
|
+
verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean;
|
|
4
|
+
hashPasswordThreadPool(password: string): string;
|
|
3
5
|
hashPassword(password: string): string;
|
|
4
6
|
verify(hashedPassword: string, passwordToVerify: string): boolean;
|
|
5
7
|
}
|
|
@@ -3,6 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ScryptWrapper = void 0;
|
|
4
4
|
const index_1 = require("../../index");
|
|
5
5
|
class ScryptWrapper {
|
|
6
|
+
verifyThreadPool(hashedPassword, passwordToCheck) {
|
|
7
|
+
if (!hashedPassword || !passwordToCheck) {
|
|
8
|
+
throw new Error("You must provide a hashed password and a plaintext password to verify with Scrypt");
|
|
9
|
+
}
|
|
10
|
+
return (0, index_1.scryptVerifyThreadpool)(hashedPassword, passwordToCheck);
|
|
11
|
+
}
|
|
12
|
+
hashPasswordThreadPool(password) {
|
|
13
|
+
if (!password) {
|
|
14
|
+
throw new Error("You must provide a password to hash with Scrypt");
|
|
15
|
+
}
|
|
16
|
+
return (0, index_1.scryptHashThreadpool)(password);
|
|
17
|
+
}
|
|
6
18
|
hashPassword(password) {
|
|
7
19
|
if (!password) {
|
|
8
20
|
throw new Error("You must provide a password to hash with Scrypt");
|
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,9 +1,27 @@
|
|
|
1
|
-
import {argon2Hash, argon2Verify} from "./../../index";
|
|
2
|
-
import { IPasswordHasherBase} from "./password-hasher-base";
|
|
1
|
+
import { argon2Hash, argon2HashThreadPool, argon2Verify, argon2VerifyThreadpool } from "./../../index";
|
|
2
|
+
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
3
3
|
|
|
4
4
|
export class Argon2Wrapper implements IPasswordHasherBase {
|
|
5
|
+
|
|
6
|
+
verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean {
|
|
7
|
+
if (!hashedPassword) {
|
|
8
|
+
throw new Error("You must provide a password to verify with Argon2");
|
|
9
|
+
}
|
|
10
|
+
if (!passwordToCheck) {
|
|
11
|
+
throw new Error("You must provide a password to check to verify with Argon2");
|
|
12
|
+
}
|
|
13
|
+
return argon2VerifyThreadpool(hashedPassword, passwordToCheck);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public hashPasswordThreadPool(password: string): string {
|
|
17
|
+
if (!password) {
|
|
18
|
+
throw new Error("You must provide a password to hash with Argon2");
|
|
19
|
+
}
|
|
20
|
+
return argon2HashThreadPool(password);
|
|
21
|
+
}
|
|
22
|
+
|
|
5
23
|
public hashPassword(password: string): string {
|
|
6
|
-
if (!password){
|
|
24
|
+
if (!password) {
|
|
7
25
|
throw new Error("You must provide a password to hash with Argon2");
|
|
8
26
|
}
|
|
9
27
|
return argon2Hash(password);
|
|
@@ -11,7 +29,9 @@ export class Argon2Wrapper implements IPasswordHasherBase {
|
|
|
11
29
|
|
|
12
30
|
public verify(hashedPassword: string, passwordToVerify: string): boolean {
|
|
13
31
|
if (!hashedPassword || !passwordToVerify) {
|
|
14
|
-
throw new Error(
|
|
32
|
+
throw new Error(
|
|
33
|
+
"You must provide a hashed password and a plaintext password to verify with Argon2",
|
|
34
|
+
);
|
|
15
35
|
}
|
|
16
36
|
return argon2Verify(hashedPassword, passwordToVerify);
|
|
17
37
|
}
|
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
2
|
-
import { bcryptHash, bcryptVerify } from "./../../index";
|
|
2
|
+
import { bcryptHash, bcryptHashThreadpool, bcryptVerify, bcryptVerifyThreadpool } from "./../../index";
|
|
3
3
|
|
|
4
4
|
export class BCryptWrapper implements IPasswordHasherBase {
|
|
5
|
+
|
|
6
|
+
verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean {
|
|
7
|
+
if (!hashedPassword || !passwordToCheck) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"You must provide a hashed password and a plaintext password to verify with Argon2",
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
return bcryptVerifyThreadpool(hashedPassword, passwordToCheck);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public hashPasswordThreadPool(password: string): string {
|
|
16
|
+
if (!password) {
|
|
17
|
+
throw new Error("You must provide a password to hash with Argon2");
|
|
18
|
+
}
|
|
19
|
+
return bcryptHashThreadpool(password);
|
|
20
|
+
}
|
|
21
|
+
|
|
5
22
|
public hashPassword(password: string): string {
|
|
6
23
|
if (!password) {
|
|
7
24
|
throw new Error("You must provide a password to hash 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,20 +1,37 @@
|
|
|
1
|
-
import { scryptHash, scryptVerify } from "../../index";
|
|
1
|
+
import { scryptHash, scryptHashThreadpool, scryptVerify, scryptVerifyThreadpool } from "../../index";
|
|
2
2
|
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
3
3
|
|
|
4
4
|
export class ScryptWrapper implements IPasswordHasherBase {
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (!hashedPassword || !passwordToVerify) {
|
|
15
|
-
throw new Error("You must provide a hashed password and a plaintext password to verify with Scrypt");
|
|
16
|
-
}
|
|
17
|
-
return scryptVerify(hashedPassword, passwordToVerify);
|
|
18
|
-
}
|
|
6
|
+
verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean {
|
|
7
|
+
if (!hashedPassword || !passwordToCheck) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"You must provide a hashed password and a plaintext password to verify with Scrypt",
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
return scryptVerifyThreadpool(hashedPassword, passwordToCheck);
|
|
13
|
+
}
|
|
19
14
|
|
|
20
|
-
|
|
15
|
+
hashPasswordThreadPool(password: string): string {
|
|
16
|
+
if (!password) {
|
|
17
|
+
throw new Error("You must provide a password to hash with Scrypt");
|
|
18
|
+
}
|
|
19
|
+
return scryptHashThreadpool(password);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public hashPassword(password: string): string {
|
|
23
|
+
if (!password) {
|
|
24
|
+
throw new Error("You must provide a password to hash with Scrypt");
|
|
25
|
+
}
|
|
26
|
+
return scryptHash(password);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public verify(hashedPassword: string, passwordToVerify: string): boolean {
|
|
30
|
+
if (!hashedPassword || !passwordToVerify) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
"You must provide a hashed password and a plaintext password to verify with Scrypt",
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return scryptVerify(hashedPassword, passwordToVerify);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assert, expect } from "chai";
|
|
2
|
-
import { BCryptWrapper } from "../src-ts/password-hashers/index";
|
|
2
|
+
import { Argon2Wrapper, BCryptWrapper } from "../src-ts/password-hashers/index";
|
|
3
3
|
import { ScryptWrapper } from "../src-ts/password-hashers/index";
|
|
4
4
|
import {
|
|
5
5
|
PasswordHasherFactory,
|
|
@@ -7,6 +7,22 @@ import {
|
|
|
7
7
|
} from "../src-ts/password-hashers";
|
|
8
8
|
|
|
9
9
|
describe("Bcrypt Tests", () => {
|
|
10
|
+
|
|
11
|
+
it("hash threadpool", () => {
|
|
12
|
+
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
13
|
+
const password: string = "ThisOneBadPassword!@";
|
|
14
|
+
const hashedPassword: string = hasher.hashPasswordThreadPool(password);
|
|
15
|
+
assert.notEqual(hashedPassword, password);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("verify threadpool", () => {
|
|
19
|
+
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
20
|
+
const password: string = "NotThisPassword!@";
|
|
21
|
+
const hashedPassword: string = hasher.hashPassword(password);
|
|
22
|
+
const isValid: boolean = hasher.verifyThreadPool(hashedPassword, password);
|
|
23
|
+
expect(isValid).to.equal(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
10
26
|
it("hash", () => {
|
|
11
27
|
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
12
28
|
const password: string = "ThisOneBadPassword!@";
|
|
@@ -35,6 +51,25 @@ describe("Bcrypt Tests", () => {
|
|
|
35
51
|
});
|
|
36
52
|
|
|
37
53
|
describe("Scrypt Tests", () => {
|
|
54
|
+
it("hash with threadpool", () => {
|
|
55
|
+
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
56
|
+
PasswordHasherType.Scrypt,
|
|
57
|
+
);
|
|
58
|
+
const password: string = "ScryptRocks";
|
|
59
|
+
const hashed: string = hasher.hashPasswordThreadPool(password);
|
|
60
|
+
assert.notEqual(password, hashed);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("verify pass with threadpool", () => {
|
|
64
|
+
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
65
|
+
PasswordHasherType.Scrypt,
|
|
66
|
+
);
|
|
67
|
+
const password: string = "ScryptRocks1231231";
|
|
68
|
+
const hashed: string = hasher.hashPasswordThreadPool(password);
|
|
69
|
+
const verified: boolean = hasher.verifyThreadPool(hashed, password);
|
|
70
|
+
assert.isTrue(verified);
|
|
71
|
+
});
|
|
72
|
+
|
|
38
73
|
it("hash with factory", () => {
|
|
39
74
|
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
40
75
|
PasswordHasherType.Scrypt,
|
|
@@ -69,8 +104,23 @@ describe("Scrypt Tests", () => {
|
|
|
69
104
|
});
|
|
70
105
|
|
|
71
106
|
describe("Argon2 Tests", () => {
|
|
107
|
+
it("hash with threadpool", () => {
|
|
108
|
+
const argon2: Argon2Wrapper = PasswordHasherFactory.getHasher(PasswordHasherType.Argon2);
|
|
109
|
+
const password = "Argon2OverBCrypt";
|
|
110
|
+
const hashed = argon2.hashPasswordThreadPool(password);
|
|
111
|
+
assert.notEqual(password, hashed);
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it("verify with threadpool", () => {
|
|
115
|
+
const argon2: Argon2Wrapper = PasswordHasherFactory.getHasher(PasswordHasherType.Argon2);
|
|
116
|
+
const password = "Argon2OverBCrypt";
|
|
117
|
+
const hashed = argon2.hashPasswordThreadPool(password);
|
|
118
|
+
const result = argon2.verifyThreadPool(hashed, password);
|
|
119
|
+
assert.equal(result, true);
|
|
120
|
+
});
|
|
121
|
+
|
|
72
122
|
it("hash with factory", () => {
|
|
73
|
-
const hasher:
|
|
123
|
+
const hasher: Argon2Wrapper = PasswordHasherFactory.getHasher(
|
|
74
124
|
PasswordHasherType.Argon2,
|
|
75
125
|
);
|
|
76
126
|
const password: string = "ScryptRocks";
|
|
@@ -79,7 +129,7 @@ describe("Argon2 Tests", () => {
|
|
|
79
129
|
});
|
|
80
130
|
|
|
81
131
|
it("verify pass with factory", () => {
|
|
82
|
-
const hasher:
|
|
132
|
+
const hasher: Argon2Wrapper = PasswordHasherFactory.getHasher(
|
|
83
133
|
PasswordHasherType.Argon2,
|
|
84
134
|
);
|
|
85
135
|
const password: string = "ScryptRocks1231231";
|