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
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { RsaDigitalSignatureResult, SHAED25519DalekDigitalSignatureResult, Shaed25519DalekDigitalSignatureResult, sha256Ed25519DigitalSignature, sha256Ed25519DigitalSignatureVerify, sha256RsaDigitalSignature, sha256RsaVerifyDigitalSignature, sha512Ed25519DigitalSignature } from "../../index";
|
|
2
|
+
import { IDigitalSignature } from "./digital-signature-base";
|
|
3
|
+
|
|
4
|
+
export class DigitalSignatureSHA256Wrapper implements IDigitalSignature {
|
|
5
|
+
|
|
6
|
+
createED25519(dataToSign: number[]): Shaed25519DalekDigitalSignatureResult {
|
|
7
|
+
if (dataToSign?.length === 0) {
|
|
8
|
+
throw new Error("Must provide allocated data to sign");
|
|
9
|
+
}
|
|
10
|
+
return sha256Ed25519DigitalSignature(dataToSign);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
verifyED25519(publicKey: number[], dataToVerify: number[], signature: number[]): boolean {
|
|
14
|
+
if (!publicKey) {
|
|
15
|
+
throw new Error("You must provide a public key for verify with ED25519");
|
|
16
|
+
}
|
|
17
|
+
if (dataToVerify?.length === 0) {
|
|
18
|
+
throw new Error("Must provide allocated data to verify");
|
|
19
|
+
}
|
|
20
|
+
if (signature?.length === 0) {
|
|
21
|
+
throw new Error("Must provide allocated signature to verify");
|
|
22
|
+
}
|
|
23
|
+
return sha256Ed25519DigitalSignatureVerify(publicKey, dataToVerify, signature);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
createRsa(rsa_key_size: number, data_to_sign: number[]): RsaDigitalSignatureResult {
|
|
27
|
+
if (rsa_key_size !== 1024 && rsa_key_size !== 2048 && rsa_key_size !== 4096) {
|
|
28
|
+
throw new Error("You need to provide an appropriate RSA key size.");
|
|
29
|
+
}
|
|
30
|
+
if (data_to_sign?.length === 0) {
|
|
31
|
+
throw new Error("Must provide allocated data to sign");
|
|
32
|
+
}
|
|
33
|
+
return sha256RsaDigitalSignature(rsa_key_size, data_to_sign);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
verifyRSa(public_key: string, data_to_verify: number[], signature: number[]): boolean {
|
|
37
|
+
if (!public_key) {
|
|
38
|
+
throw new Error("Must provide a public key");
|
|
39
|
+
}
|
|
40
|
+
if (data_to_verify?.length === 0) {
|
|
41
|
+
throw new Error("Must provide an allocated data to verify");
|
|
42
|
+
}
|
|
43
|
+
if (signature?.length === 0) {
|
|
44
|
+
throw new Error("Must provide an allocated signature");
|
|
45
|
+
}
|
|
46
|
+
return sha256RsaVerifyDigitalSignature(public_key, data_to_verify, signature);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DigitalSignatureType } from "./digital-signature-factory";
|
|
2
|
+
import { DigitalSignatureFactory } from "./digital-signature-factory";
|
|
3
|
+
import { DigitalSignatureSHA256Wrapper } from "./digital-signaturte-sha-256";
|
|
4
|
+
import { DigitalSignatureSHA512Wrapper } from "./digital-siganture-sha-512";
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
DigitalSignatureFactory,
|
|
8
|
+
DigitalSignatureSHA256Wrapper,
|
|
9
|
+
DigitalSignatureSHA512Wrapper,
|
|
10
|
+
DigitalSignatureType
|
|
11
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export interface IHasherBase {
|
|
2
|
-
hash_512(dataToHash: number[]): number[];
|
|
3
|
-
verify_512(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
4
|
-
hash_256(dataToHash: number[]): number[];
|
|
5
|
-
verify_256(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
1
|
+
export interface IHasherBase {
|
|
2
|
+
hash_512(dataToHash: number[]): number[];
|
|
3
|
+
verify_512(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
4
|
+
hash_256(dataToHash: number[]): number[];
|
|
5
|
+
verify_256(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
6
6
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { HasherType } from "./hasher-type";
|
|
2
|
-
import { SHAWrapper } from "./sha-wrapper";
|
|
3
|
-
|
|
4
|
-
export class HasherFactory {
|
|
5
|
-
getHasher(type: HasherType): any {
|
|
6
|
-
let result: SHAWrapper = new SHAWrapper();
|
|
7
|
-
switch(type) {
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
return result;
|
|
11
|
-
}
|
|
1
|
+
import { HasherType } from "./hasher-type";
|
|
2
|
+
import { SHAWrapper } from "./sha-wrapper";
|
|
3
|
+
|
|
4
|
+
export class HasherFactory {
|
|
5
|
+
getHasher(type: HasherType): any {
|
|
6
|
+
let result: SHAWrapper = new SHAWrapper();
|
|
7
|
+
switch(type) {
|
|
8
|
+
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
12
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export enum HasherType {
|
|
2
|
-
SHA = 1
|
|
1
|
+
export enum HasherType {
|
|
2
|
+
SHA = 1
|
|
3
3
|
}
|
package/src-ts/hashers/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HasherFactory } from "./hasher-factory";
|
|
2
|
-
import { HasherType } from "./hasher-type";
|
|
3
|
-
import { SHAWrapper } from "./sha-wrapper";
|
|
4
|
-
|
|
5
|
-
export { SHAWrapper, HasherFactory, HasherType };
|
|
1
|
+
import { HasherFactory } from "./hasher-factory";
|
|
2
|
+
import { HasherType } from "./hasher-type";
|
|
3
|
+
import { SHAWrapper } from "./sha-wrapper";
|
|
4
|
+
|
|
5
|
+
export { SHAWrapper, HasherFactory, HasherType };
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { sha256, sha256Verify, sha512, sha512Verify } from "../../index";
|
|
2
|
-
import { IHasherBase } from "./hasher-base";
|
|
3
|
-
|
|
4
|
-
export class SHAWrapper implements IHasherBase {
|
|
5
|
-
hash_512(dataToHash: number[]): number[] {
|
|
6
|
-
if (!dataToHash || dataToHash.length === 0) {
|
|
7
|
-
throw new Error("You must provide an allocated array of data");
|
|
8
|
-
}
|
|
9
|
-
return sha512(dataToHash);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
verify_512(dataToHash: number[], dataToVerify: number[]): boolean {
|
|
13
|
-
if (!dataToHash || dataToHash.length === 0) {
|
|
14
|
-
throw new Error("You must provide an allocated array of data");
|
|
15
|
-
}
|
|
16
|
-
if (!dataToVerify || dataToVerify.length === 0) {
|
|
17
|
-
throw new Error("You must provide an allocated array of data to verify");
|
|
18
|
-
}
|
|
19
|
-
return sha512Verify(dataToHash, dataToVerify);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
hash_256(dataToHash: number[]): number[] {
|
|
23
|
-
if (!dataToHash || dataToHash.length === 0) {
|
|
24
|
-
throw new Error("You must provide an allocated array of data");
|
|
25
|
-
}
|
|
26
|
-
return sha256(dataToHash);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
verify_256(dataToHash: number[], dataToVerify: number[]): boolean {
|
|
30
|
-
if (!dataToHash || dataToHash.length === 0) {
|
|
31
|
-
throw new Error("You must provide an allocated array of data");
|
|
32
|
-
}
|
|
33
|
-
if (!dataToVerify || dataToVerify.length === 0) {
|
|
34
|
-
throw new Error("You must provide an allocated array of data to verify");
|
|
35
|
-
}
|
|
36
|
-
return sha256Verify(dataToHash, dataToVerify);
|
|
37
|
-
}
|
|
1
|
+
import { sha256, sha256Verify, sha512, sha512Verify } from "../../index";
|
|
2
|
+
import { IHasherBase } from "./hasher-base";
|
|
3
|
+
|
|
4
|
+
export class SHAWrapper implements IHasherBase {
|
|
5
|
+
hash_512(dataToHash: number[]): number[] {
|
|
6
|
+
if (!dataToHash || dataToHash.length === 0) {
|
|
7
|
+
throw new Error("You must provide an allocated array of data");
|
|
8
|
+
}
|
|
9
|
+
return sha512(dataToHash);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
verify_512(dataToHash: number[], dataToVerify: number[]): boolean {
|
|
13
|
+
if (!dataToHash || dataToHash.length === 0) {
|
|
14
|
+
throw new Error("You must provide an allocated array of data");
|
|
15
|
+
}
|
|
16
|
+
if (!dataToVerify || dataToVerify.length === 0) {
|
|
17
|
+
throw new Error("You must provide an allocated array of data to verify");
|
|
18
|
+
}
|
|
19
|
+
return sha512Verify(dataToHash, dataToVerify);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
hash_256(dataToHash: number[]): number[] {
|
|
23
|
+
if (!dataToHash || dataToHash.length === 0) {
|
|
24
|
+
throw new Error("You must provide an allocated array of data");
|
|
25
|
+
}
|
|
26
|
+
return sha256(dataToHash);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
verify_256(dataToHash: number[], dataToVerify: number[]): boolean {
|
|
30
|
+
if (!dataToHash || dataToHash.length === 0) {
|
|
31
|
+
throw new Error("You must provide an allocated array of data");
|
|
32
|
+
}
|
|
33
|
+
if (!dataToVerify || dataToVerify.length === 0) {
|
|
34
|
+
throw new Error("You must provide an allocated array of data to verify");
|
|
35
|
+
}
|
|
36
|
+
return sha256Verify(dataToHash, dataToVerify);
|
|
37
|
+
}
|
|
38
38
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as crypto from "crypto";
|
|
2
|
-
|
|
3
|
-
export class NonceGenerator {
|
|
4
|
-
|
|
5
|
-
public generateNonce(): string {
|
|
6
|
-
const nonceBytes = crypto.randomBytes(12);
|
|
7
|
-
return nonceBytes.toString('hex').substring(0, 12);
|
|
8
|
-
}
|
|
1
|
+
import * as crypto from "crypto";
|
|
2
|
+
|
|
3
|
+
export class NonceGenerator {
|
|
4
|
+
|
|
5
|
+
public generateNonce(): string {
|
|
6
|
+
const nonceBytes = crypto.randomBytes(12);
|
|
7
|
+
return nonceBytes.toString('hex').substring(0, 12);
|
|
8
|
+
}
|
|
9
9
|
}
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import { RSAWrapper } from "../asymmetric";
|
|
2
|
-
import { AESWrapper } from "../symmetric";
|
|
3
|
-
import { AesRsaHybridEncryptResult } from "./types/aes-rsa-hybird-encrypt-result";
|
|
4
|
-
import { AESRSAHybridInitializer } from "./types/aes-rsa-hybrid-initializer";
|
|
5
|
-
|
|
6
|
-
export class HybridEncryptionWrapper {
|
|
7
|
-
private aesWrapper: AESWrapper;
|
|
8
|
-
private rsaWrapper: RSAWrapper;
|
|
9
|
-
|
|
10
|
-
constructor() {
|
|
11
|
-
this.aesWrapper = new AESWrapper();
|
|
12
|
-
this.rsaWrapper = new RSAWrapper();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public encrypt(
|
|
16
|
-
dataToEncrypt: Array<number>,
|
|
17
|
-
initalizer: AESRSAHybridInitializer,
|
|
18
|
-
): AesRsaHybridEncryptResult {
|
|
19
|
-
let encryptedData: Array<number> = (initalizer.aesType === 128)
|
|
20
|
-
? this.aesWrapper.aes128Encrypt(
|
|
21
|
-
initalizer.aesKey,
|
|
22
|
-
initalizer.aesNonce,
|
|
23
|
-
dataToEncrypt,
|
|
24
|
-
)
|
|
25
|
-
: this.aesWrapper.aes256Encrypt(
|
|
26
|
-
initalizer.aesKey,
|
|
27
|
-
initalizer.aesNonce,
|
|
28
|
-
dataToEncrypt,
|
|
29
|
-
);
|
|
30
|
-
let encryptedAesKey: Array<number> = this.rsaWrapper.encrypt(
|
|
31
|
-
initalizer.rsaKeyPair.publicKey,
|
|
32
|
-
initalizer.aesKey,
|
|
33
|
-
);
|
|
34
|
-
let result: AesRsaHybridEncryptResult = new AesRsaHybridEncryptResult(
|
|
35
|
-
encryptedData,
|
|
36
|
-
encryptedAesKey,
|
|
37
|
-
initalizer.aesType,
|
|
38
|
-
initalizer.aesNonce,
|
|
39
|
-
);
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public decrypt(
|
|
44
|
-
privateKey: string,
|
|
45
|
-
encryptResult: AesRsaHybridEncryptResult,
|
|
46
|
-
): Array<number> {
|
|
47
|
-
let plaintextAesKey = this.rsaWrapper.decrypt(
|
|
48
|
-
privateKey,
|
|
49
|
-
encryptResult.encryptedAesKey,
|
|
50
|
-
);
|
|
51
|
-
let plaintext = (encryptResult.aesType === 128)
|
|
52
|
-
? this.aesWrapper.aes128Decrypt(
|
|
53
|
-
plaintextAesKey,
|
|
54
|
-
encryptResult.aesNonce,
|
|
55
|
-
encryptResult.ciphertext,
|
|
56
|
-
)
|
|
57
|
-
: this.aesWrapper.aes256Decrypt(
|
|
58
|
-
plaintextAesKey,
|
|
59
|
-
encryptResult.aesNonce,
|
|
60
|
-
encryptResult.ciphertext,
|
|
61
|
-
);
|
|
62
|
-
return plaintext;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
1
|
+
import { RSAWrapper } from "../asymmetric";
|
|
2
|
+
import { AESWrapper } from "../symmetric";
|
|
3
|
+
import { AesRsaHybridEncryptResult } from "./types/aes-rsa-hybird-encrypt-result";
|
|
4
|
+
import { AESRSAHybridInitializer } from "./types/aes-rsa-hybrid-initializer";
|
|
5
|
+
|
|
6
|
+
export class HybridEncryptionWrapper {
|
|
7
|
+
private aesWrapper: AESWrapper;
|
|
8
|
+
private rsaWrapper: RSAWrapper;
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
this.aesWrapper = new AESWrapper();
|
|
12
|
+
this.rsaWrapper = new RSAWrapper();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public encrypt(
|
|
16
|
+
dataToEncrypt: Array<number>,
|
|
17
|
+
initalizer: AESRSAHybridInitializer,
|
|
18
|
+
): AesRsaHybridEncryptResult {
|
|
19
|
+
let encryptedData: Array<number> = (initalizer.aesType === 128)
|
|
20
|
+
? this.aesWrapper.aes128Encrypt(
|
|
21
|
+
initalizer.aesKey,
|
|
22
|
+
initalizer.aesNonce,
|
|
23
|
+
dataToEncrypt,
|
|
24
|
+
)
|
|
25
|
+
: this.aesWrapper.aes256Encrypt(
|
|
26
|
+
initalizer.aesKey,
|
|
27
|
+
initalizer.aesNonce,
|
|
28
|
+
dataToEncrypt,
|
|
29
|
+
);
|
|
30
|
+
let encryptedAesKey: Array<number> = this.rsaWrapper.encrypt(
|
|
31
|
+
initalizer.rsaKeyPair.publicKey,
|
|
32
|
+
initalizer.aesKey,
|
|
33
|
+
);
|
|
34
|
+
let result: AesRsaHybridEncryptResult = new AesRsaHybridEncryptResult(
|
|
35
|
+
encryptedData,
|
|
36
|
+
encryptedAesKey,
|
|
37
|
+
initalizer.aesType,
|
|
38
|
+
initalizer.aesNonce,
|
|
39
|
+
);
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public decrypt(
|
|
44
|
+
privateKey: string,
|
|
45
|
+
encryptResult: AesRsaHybridEncryptResult,
|
|
46
|
+
): Array<number> {
|
|
47
|
+
let plaintextAesKey = this.rsaWrapper.decrypt(
|
|
48
|
+
privateKey,
|
|
49
|
+
encryptResult.encryptedAesKey,
|
|
50
|
+
);
|
|
51
|
+
let plaintext = (encryptResult.aesType === 128)
|
|
52
|
+
? this.aesWrapper.aes128Decrypt(
|
|
53
|
+
plaintextAesKey,
|
|
54
|
+
encryptResult.aesNonce,
|
|
55
|
+
encryptResult.ciphertext,
|
|
56
|
+
)
|
|
57
|
+
: this.aesWrapper.aes256Decrypt(
|
|
58
|
+
plaintextAesKey,
|
|
59
|
+
encryptResult.aesNonce,
|
|
60
|
+
encryptResult.ciphertext,
|
|
61
|
+
);
|
|
62
|
+
return plaintext;
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src-ts/hybrid/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { HybridEncryptionWrapper } from "./hybrid-encryption-wrapper";
|
|
2
|
-
import { AesRsaHybridEncryptResult } from "./types/aes-rsa-hybird-encrypt-result";
|
|
3
|
-
import { AESRSAHybridInitializer } from "./types/aes-rsa-hybrid-initializer";
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
AesRsaHybridEncryptResult,
|
|
7
|
-
AESRSAHybridInitializer,
|
|
8
|
-
HybridEncryptionWrapper,
|
|
9
|
-
};
|
|
1
|
+
import { HybridEncryptionWrapper } from "./hybrid-encryption-wrapper";
|
|
2
|
+
import { AesRsaHybridEncryptResult } from "./types/aes-rsa-hybird-encrypt-result";
|
|
3
|
+
import { AESRSAHybridInitializer } from "./types/aes-rsa-hybrid-initializer";
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
AesRsaHybridEncryptResult,
|
|
7
|
+
AESRSAHybridInitializer,
|
|
8
|
+
HybridEncryptionWrapper,
|
|
9
|
+
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export class AesRsaHybridEncryptResult {
|
|
2
|
-
ciphertext: Array<number>;
|
|
3
|
-
encryptedAesKey: Array<number>;
|
|
4
|
-
aesType: number;
|
|
5
|
-
aesNonce: Array<number>;
|
|
6
|
-
|
|
7
|
-
constructor(cipherText: Array<number>, encryptAesKey: Array<number>, aesType: number, aesNonce: Array<number>) {
|
|
8
|
-
this.ciphertext = cipherText;
|
|
9
|
-
this.encryptedAesKey = encryptAesKey;
|
|
10
|
-
this.aesType = aesType;
|
|
11
|
-
this.aesNonce = aesNonce;
|
|
12
|
-
}
|
|
1
|
+
export class AesRsaHybridEncryptResult {
|
|
2
|
+
ciphertext: Array<number>;
|
|
3
|
+
encryptedAesKey: Array<number>;
|
|
4
|
+
aesType: number;
|
|
5
|
+
aesNonce: Array<number>;
|
|
6
|
+
|
|
7
|
+
constructor(cipherText: Array<number>, encryptAesKey: Array<number>, aesType: number, aesNonce: Array<number>) {
|
|
8
|
+
this.ciphertext = cipherText;
|
|
9
|
+
this.encryptedAesKey = encryptAesKey;
|
|
10
|
+
this.aesType = aesType;
|
|
11
|
+
this.aesNonce = aesNonce;
|
|
12
|
+
}
|
|
13
13
|
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { RsaKeyPairResult } from "../../..";
|
|
2
|
-
import { RSAWrapper } from "../../asymmetric";
|
|
3
|
-
import { AESWrapper } from "../../symmetric";
|
|
4
|
-
|
|
5
|
-
export class AESRSAHybridInitializer {
|
|
6
|
-
public aesType: number;
|
|
7
|
-
public aesKey: Array<number>;
|
|
8
|
-
public aesNonce: Array<number>;
|
|
9
|
-
public rsaKeyPair: RsaKeyPairResult;
|
|
10
|
-
|
|
11
|
-
constructor(aesType: number, rsaSize: number) {
|
|
12
|
-
if (aesType !== 128 && aesType !== 256) {
|
|
13
|
-
throw new Error("Need an appropriate AES size to generate a hybrid initalizer");
|
|
14
|
-
}
|
|
15
|
-
this.aesType = aesType;
|
|
16
|
-
let aesWrapper = new AESWrapper();
|
|
17
|
-
this.aesKey = (aesType === 128) ? aesWrapper.aes128Key() : aesWrapper.aes256Key();
|
|
18
|
-
this.aesNonce = aesWrapper.aesNonce();
|
|
19
|
-
if (rsaSize !== 1028 && rsaSize !== 2048 && rsaSize !== 4096) {
|
|
20
|
-
throw new Error("You must provide an appropriate RSA Key pair size to generate a hybrid initalizer");
|
|
21
|
-
}
|
|
22
|
-
this.rsaKeyPair = new RSAWrapper().generateKeys(rsaSize);
|
|
23
|
-
}
|
|
1
|
+
import { RsaKeyPairResult } from "../../..";
|
|
2
|
+
import { RSAWrapper } from "../../asymmetric";
|
|
3
|
+
import { AESWrapper } from "../../symmetric";
|
|
4
|
+
|
|
5
|
+
export class AESRSAHybridInitializer {
|
|
6
|
+
public aesType: number;
|
|
7
|
+
public aesKey: Array<number>;
|
|
8
|
+
public aesNonce: Array<number>;
|
|
9
|
+
public rsaKeyPair: RsaKeyPairResult;
|
|
10
|
+
|
|
11
|
+
constructor(aesType: number, rsaSize: number) {
|
|
12
|
+
if (aesType !== 128 && aesType !== 256) {
|
|
13
|
+
throw new Error("Need an appropriate AES size to generate a hybrid initalizer");
|
|
14
|
+
}
|
|
15
|
+
this.aesType = aesType;
|
|
16
|
+
let aesWrapper = new AESWrapper();
|
|
17
|
+
this.aesKey = (aesType === 128) ? aesWrapper.aes128Key() : aesWrapper.aes256Key();
|
|
18
|
+
this.aesNonce = aesWrapper.aesNonce();
|
|
19
|
+
if (rsaSize !== 1028 && rsaSize !== 2048 && rsaSize !== 4096) {
|
|
20
|
+
throw new Error("You must provide an appropriate RSA Key pair size to generate a hybrid initalizer");
|
|
21
|
+
}
|
|
22
|
+
this.rsaKeyPair = new RSAWrapper().generateKeys(rsaSize);
|
|
23
|
+
}
|
|
24
24
|
}
|
package/src-ts/index.ts
CHANGED
|
@@ -1,34 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Argon2Wrapper,
|
|
3
|
-
BCryptWrapper,
|
|
4
|
-
PasswordHasherFactory,
|
|
5
|
-
PasswordHasherType,
|
|
6
|
-
ScryptWrapper,
|
|
7
|
-
} from "./password-hashers/index";
|
|
8
|
-
import { HasherFactory, HasherType, SHAWrapper } from "./hashers/index";
|
|
9
|
-
import { X25519Wrapper } from "./key_exchange/index";
|
|
10
|
-
import { AESWrapper } from "./symmetric/index";
|
|
11
|
-
import { RsaKeyPairResult, RSAWrapper } from "./asymmetric/index";
|
|
12
|
-
import {
|
|
13
|
-
AesRsaHybridEncryptResult,
|
|
14
|
-
AESRSAHybridInitializer,
|
|
15
|
-
HybridEncryptionWrapper,
|
|
16
|
-
} from "./hybrid/index";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
import {
|
|
2
|
+
Argon2Wrapper,
|
|
3
|
+
BCryptWrapper,
|
|
4
|
+
PasswordHasherFactory,
|
|
5
|
+
PasswordHasherType,
|
|
6
|
+
ScryptWrapper,
|
|
7
|
+
} from "./password-hashers/index";
|
|
8
|
+
import { HasherFactory, HasherType, SHAWrapper } from "./hashers/index";
|
|
9
|
+
import { X25519Wrapper } from "./key_exchange/index";
|
|
10
|
+
import { AESWrapper } from "./symmetric/index";
|
|
11
|
+
import { RsaKeyPairResult, RSAWrapper } from "./asymmetric/index";
|
|
12
|
+
import {
|
|
13
|
+
AesRsaHybridEncryptResult,
|
|
14
|
+
AESRSAHybridInitializer,
|
|
15
|
+
HybridEncryptionWrapper,
|
|
16
|
+
} from "./hybrid/index";
|
|
17
|
+
import {
|
|
18
|
+
DigitalSignatureFactory,
|
|
19
|
+
DigitalSignatureSHA256Wrapper,
|
|
20
|
+
DigitalSignatureSHA512Wrapper,
|
|
21
|
+
DigitalSignatureType,
|
|
22
|
+
} from "./digital-signature";
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
AesRsaHybridEncryptResult,
|
|
26
|
+
AESRSAHybridInitializer,
|
|
27
|
+
AESWrapper,
|
|
28
|
+
Argon2Wrapper,
|
|
29
|
+
BCryptWrapper,
|
|
30
|
+
HasherFactory,
|
|
31
|
+
HasherType,
|
|
32
|
+
HybridEncryptionWrapper,
|
|
33
|
+
PasswordHasherFactory,
|
|
34
|
+
PasswordHasherType,
|
|
35
|
+
RsaKeyPairResult,
|
|
36
|
+
RSAWrapper,
|
|
37
|
+
ScryptWrapper,
|
|
38
|
+
SHAWrapper,
|
|
39
|
+
X25519Wrapper,
|
|
40
|
+
DigitalSignatureFactory,
|
|
41
|
+
DigitalSignatureSHA256Wrapper,
|
|
42
|
+
DigitalSignatureSHA512Wrapper,
|
|
43
|
+
DigitalSignatureType,
|
|
44
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { X25519Wrapper } from "./x25519";
|
|
2
|
-
|
|
3
|
-
export { X25519Wrapper };
|
|
1
|
+
import { X25519Wrapper } from "./x25519";
|
|
2
|
+
|
|
3
|
+
export { X25519Wrapper };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { x25519DiffieHellman, x25519GenerateSecretAndPublicKey, X25519SecretPublicKeyResult } from "../../index"
|
|
2
|
-
|
|
3
|
-
export class X25519Wrapper {
|
|
4
|
-
public generateSecretAndPublicKey(): X25519SecretPublicKeyResult {
|
|
5
|
-
return x25519GenerateSecretAndPublicKey();
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
public diffieHellman(secretKey: Array<number>, publicKey: Array<number>) {
|
|
9
|
-
return x25519DiffieHellman(secretKey, publicKey);
|
|
10
|
-
}
|
|
1
|
+
import { x25519DiffieHellman, x25519GenerateSecretAndPublicKey, X25519SecretPublicKeyResult } from "../../index"
|
|
2
|
+
|
|
3
|
+
export class X25519Wrapper {
|
|
4
|
+
public generateSecretAndPublicKey(): X25519SecretPublicKeyResult {
|
|
5
|
+
return x25519GenerateSecretAndPublicKey();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
public diffieHellman(secretKey: Array<number>, publicKey: Array<number>) {
|
|
9
|
+
return x25519DiffieHellman(secretKey, publicKey);
|
|
10
|
+
}
|
|
11
11
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {argon2Hash, argon2Verify} from "./../../index";
|
|
2
|
-
import { IPasswordHasherBase} from "./password-hasher-base";
|
|
3
|
-
|
|
4
|
-
export class Argon2Wrapper implements IPasswordHasherBase {
|
|
5
|
-
public hashPassword(password: string): string {
|
|
6
|
-
if (!password){
|
|
7
|
-
throw new Error("You must provide a password to hash with Argon2");
|
|
8
|
-
}
|
|
9
|
-
return argon2Hash(password);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public verifyPassword(hashedPassword: string, passwordToVerify: string): boolean {
|
|
13
|
-
if (!hashedPassword || !passwordToVerify) {
|
|
14
|
-
throw new Error("You must provide a hashed password and a plaintext password to verify with Argon2");
|
|
15
|
-
}
|
|
16
|
-
return argon2Verify(hashedPassword, passwordToVerify);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
1
|
+
import {argon2Hash, argon2Verify} from "./../../index";
|
|
2
|
+
import { IPasswordHasherBase} from "./password-hasher-base";
|
|
3
|
+
|
|
4
|
+
export class Argon2Wrapper implements IPasswordHasherBase {
|
|
5
|
+
public hashPassword(password: string): string {
|
|
6
|
+
if (!password){
|
|
7
|
+
throw new Error("You must provide a password to hash with Argon2");
|
|
8
|
+
}
|
|
9
|
+
return argon2Hash(password);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public verifyPassword(hashedPassword: string, passwordToVerify: string): boolean {
|
|
13
|
+
if (!hashedPassword || !passwordToVerify) {
|
|
14
|
+
throw new Error("You must provide a hashed password and a plaintext password to verify with Argon2");
|
|
15
|
+
}
|
|
16
|
+
return argon2Verify(hashedPassword, passwordToVerify);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
2
|
-
import { bcryptHash, bcryptVerify } from "./../../index";
|
|
3
|
-
|
|
4
|
-
export class BCryptWrapper implements IPasswordHasherBase {
|
|
5
|
-
public hashPassword(password: string): string {
|
|
6
|
-
if (!password) {
|
|
7
|
-
throw new Error("You must provide a password to hash with Argon2");
|
|
8
|
-
}
|
|
9
|
-
return bcryptHash(password);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public verifyPassword(
|
|
13
|
-
hashedPassword: string,
|
|
14
|
-
passwordToVerify: string,
|
|
15
|
-
): boolean {
|
|
16
|
-
if (!hashedPassword || !passwordToVerify) {
|
|
17
|
-
throw new Error(
|
|
18
|
-
"You must provide a hashed password and a plaintext password to verify with Argon2",
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
return bcryptVerify(hashedPassword, passwordToVerify);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
1
|
+
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
2
|
+
import { bcryptHash, bcryptVerify } from "./../../index";
|
|
3
|
+
|
|
4
|
+
export class BCryptWrapper implements IPasswordHasherBase {
|
|
5
|
+
public hashPassword(password: string): string {
|
|
6
|
+
if (!password) {
|
|
7
|
+
throw new Error("You must provide a password to hash with Argon2");
|
|
8
|
+
}
|
|
9
|
+
return bcryptHash(password);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public verifyPassword(
|
|
13
|
+
hashedPassword: string,
|
|
14
|
+
passwordToVerify: string,
|
|
15
|
+
): boolean {
|
|
16
|
+
if (!hashedPassword || !passwordToVerify) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
"You must provide a hashed password and a plaintext password to verify with Argon2",
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return bcryptVerify(hashedPassword, passwordToVerify);
|
|
22
|
+
}
|
|
23
|
+
}
|