cas-typescript-sdk 1.0.14 → 1.0.15
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/README.md +1 -1
- package/build-node.sh +2 -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 +4 -2
- 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 +12 -4
- package/test-ts/hybrid.test.spec.ts +33 -0
- package/lib/cas_core_lib.dll +0 -0
- package/lib/hashers/IHasherBase.d.ts +0 -6
- package/lib/hashers/IHasherBase.js +0 -2
- 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/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# cas-typescript-sdk
|
|
2
2
|
|
|
3
3
|
Ever wanted all of your most useful cryptograpihc operations in one module and not have to surf documentation for various packages?
|
|
4
4
|
CAS is here to provide a unified development experience as an abstract layer to the RustCrypto and Dalek-Cryptography suite of algorithms.
|
package/build-node.sh
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AesRsaHybridEncryptResult } from "./types/aes-rsa-hybird-encrypt-result";
|
|
2
|
+
import { AESRSAHybridInitializer } from "./types/aes-rsa-hybrid-initializer";
|
|
3
|
+
export declare class HybridEncryptionWrapper {
|
|
4
|
+
private aesWrapper;
|
|
5
|
+
private rsaWrapper;
|
|
6
|
+
constructor();
|
|
7
|
+
encrypt(dataToEncrypt: Array<number>, initalizer: AESRSAHybridInitializer): AesRsaHybridEncryptResult;
|
|
8
|
+
decrypt(privateKey: string, encryptResult: AesRsaHybridEncryptResult): Array<number>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HybridEncryptionWrapper = void 0;
|
|
4
|
+
const asymmetric_1 = require("../asymmetric");
|
|
5
|
+
const symmetric_1 = require("../symmetric");
|
|
6
|
+
const aes_rsa_hybird_encrypt_result_1 = require("./types/aes-rsa-hybird-encrypt-result");
|
|
7
|
+
class HybridEncryptionWrapper {
|
|
8
|
+
aesWrapper;
|
|
9
|
+
rsaWrapper;
|
|
10
|
+
constructor() {
|
|
11
|
+
this.aesWrapper = new symmetric_1.AESWrapper();
|
|
12
|
+
this.rsaWrapper = new asymmetric_1.RSAWrapper();
|
|
13
|
+
}
|
|
14
|
+
encrypt(dataToEncrypt, initalizer) {
|
|
15
|
+
let encryptedData = (initalizer.aesType === 128)
|
|
16
|
+
? this.aesWrapper.aes128Encrypt(initalizer.aesKey, initalizer.aesNonce, dataToEncrypt)
|
|
17
|
+
: this.aesWrapper.aes256Encrypt(initalizer.aesKey, initalizer.aesNonce, dataToEncrypt);
|
|
18
|
+
let encryptedAesKey = this.rsaWrapper.encrypt(initalizer.rsaKeyPair.publicKey, initalizer.aesKey);
|
|
19
|
+
let result = new aes_rsa_hybird_encrypt_result_1.AesRsaHybridEncryptResult(encryptedData, encryptedAesKey, initalizer.aesType, initalizer.aesNonce);
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
decrypt(privateKey, encryptResult) {
|
|
23
|
+
let plaintextAesKey = this.rsaWrapper.decrypt(privateKey, encryptResult.encryptedAesKey);
|
|
24
|
+
let plaintext = (encryptResult.aesType === 128)
|
|
25
|
+
? this.aesWrapper.aes128Decrypt(plaintextAesKey, encryptResult.aesNonce, encryptResult.ciphertext)
|
|
26
|
+
: this.aesWrapper.aes256Decrypt(plaintextAesKey, encryptResult.aesNonce, encryptResult.ciphertext);
|
|
27
|
+
return plaintext;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.HybridEncryptionWrapper = HybridEncryptionWrapper;
|
|
@@ -0,0 +1,4 @@
|
|
|
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
|
+
export { AesRsaHybridEncryptResult, AESRSAHybridInitializer, HybridEncryptionWrapper, };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HybridEncryptionWrapper = exports.AESRSAHybridInitializer = exports.AesRsaHybridEncryptResult = void 0;
|
|
4
|
+
const hybrid_encryption_wrapper_1 = require("./hybrid-encryption-wrapper");
|
|
5
|
+
Object.defineProperty(exports, "HybridEncryptionWrapper", { enumerable: true, get: function () { return hybrid_encryption_wrapper_1.HybridEncryptionWrapper; } });
|
|
6
|
+
const aes_rsa_hybird_encrypt_result_1 = require("./types/aes-rsa-hybird-encrypt-result");
|
|
7
|
+
Object.defineProperty(exports, "AesRsaHybridEncryptResult", { enumerable: true, get: function () { return aes_rsa_hybird_encrypt_result_1.AesRsaHybridEncryptResult; } });
|
|
8
|
+
const aes_rsa_hybrid_initializer_1 = require("./types/aes-rsa-hybrid-initializer");
|
|
9
|
+
Object.defineProperty(exports, "AESRSAHybridInitializer", { enumerable: true, get: function () { return aes_rsa_hybrid_initializer_1.AESRSAHybridInitializer; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class AesRsaHybridEncryptResult {
|
|
2
|
+
ciphertext: Array<number>;
|
|
3
|
+
encryptedAesKey: Array<number>;
|
|
4
|
+
aesType: number;
|
|
5
|
+
aesNonce: Array<number>;
|
|
6
|
+
constructor(cipherText: Array<number>, encryptAesKey: Array<number>, aesType: number, aesNonce: Array<number>);
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AesRsaHybridEncryptResult = void 0;
|
|
4
|
+
class AesRsaHybridEncryptResult {
|
|
5
|
+
ciphertext;
|
|
6
|
+
encryptedAesKey;
|
|
7
|
+
aesType;
|
|
8
|
+
aesNonce;
|
|
9
|
+
constructor(cipherText, encryptAesKey, aesType, aesNonce) {
|
|
10
|
+
this.ciphertext = cipherText;
|
|
11
|
+
this.encryptedAesKey = encryptAesKey;
|
|
12
|
+
this.aesType = aesType;
|
|
13
|
+
this.aesNonce = aesNonce;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.AesRsaHybridEncryptResult = AesRsaHybridEncryptResult;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AESRSAHybridInitializer = void 0;
|
|
4
|
+
const asymmetric_1 = require("../../asymmetric");
|
|
5
|
+
const symmetric_1 = require("../../symmetric");
|
|
6
|
+
class AESRSAHybridInitializer {
|
|
7
|
+
aesType;
|
|
8
|
+
aesKey;
|
|
9
|
+
aesNonce;
|
|
10
|
+
rsaKeyPair;
|
|
11
|
+
constructor(aesType, rsaSize) {
|
|
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 symmetric_1.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 asymmetric_1.RSAWrapper().generateKeys(rsaSize);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.AESRSAHybridInitializer = AESRSAHybridInitializer;
|
package/lib/index.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ import { Argon2Wrapper, BCryptWrapper, PasswordHasherFactory, PasswordHasherType
|
|
|
2
2
|
import { HasherFactory, HasherType, SHAWrapper } from "./hashers/index";
|
|
3
3
|
import { X25519Wrapper } from "./key_exchange/index";
|
|
4
4
|
import { AESWrapper } from "./symmetric/index";
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import { RsaKeyPairResult, RSAWrapper } from "./asymmetric/index";
|
|
6
|
+
import { AesRsaHybridEncryptResult, AESRSAHybridInitializer, HybridEncryptionWrapper } from "./hybrid/index";
|
|
7
|
+
export { AesRsaHybridEncryptResult, AESRSAHybridInitializer, AESWrapper, Argon2Wrapper, BCryptWrapper, HasherFactory, HasherType, HybridEncryptionWrapper, PasswordHasherFactory, PasswordHasherType, RsaKeyPairResult, RSAWrapper, ScryptWrapper, SHAWrapper, X25519Wrapper, };
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.X25519Wrapper = exports.SHAWrapper = exports.ScryptWrapper = exports.RSAWrapper = exports.RsaKeyPairResult = exports.PasswordHasherType = exports.PasswordHasherFactory = exports.HybridEncryptionWrapper = exports.HasherType = exports.HasherFactory = exports.BCryptWrapper = exports.Argon2Wrapper = exports.AESWrapper = exports.AESRSAHybridInitializer = exports.AesRsaHybridEncryptResult = void 0;
|
|
4
4
|
const index_1 = require("./password-hashers/index");
|
|
5
5
|
Object.defineProperty(exports, "Argon2Wrapper", { enumerable: true, get: function () { return index_1.Argon2Wrapper; } });
|
|
6
6
|
Object.defineProperty(exports, "BCryptWrapper", { enumerable: true, get: function () { return index_1.BCryptWrapper; } });
|
|
@@ -15,6 +15,10 @@ const index_3 = require("./key_exchange/index");
|
|
|
15
15
|
Object.defineProperty(exports, "X25519Wrapper", { enumerable: true, get: function () { return index_3.X25519Wrapper; } });
|
|
16
16
|
const index_4 = require("./symmetric/index");
|
|
17
17
|
Object.defineProperty(exports, "AESWrapper", { enumerable: true, get: function () { return index_4.AESWrapper; } });
|
|
18
|
-
const
|
|
19
|
-
Object.defineProperty(exports, "
|
|
20
|
-
Object.defineProperty(exports, "
|
|
18
|
+
const index_5 = require("./asymmetric/index");
|
|
19
|
+
Object.defineProperty(exports, "RsaKeyPairResult", { enumerable: true, get: function () { return index_5.RsaKeyPairResult; } });
|
|
20
|
+
Object.defineProperty(exports, "RSAWrapper", { enumerable: true, get: function () { return index_5.RSAWrapper; } });
|
|
21
|
+
const index_6 = require("./hybrid/index");
|
|
22
|
+
Object.defineProperty(exports, "AesRsaHybridEncryptResult", { enumerable: true, get: function () { return index_6.AesRsaHybridEncryptResult; } });
|
|
23
|
+
Object.defineProperty(exports, "AESRSAHybridInitializer", { enumerable: true, get: function () { return index_6.AESRSAHybridInitializer; } });
|
|
24
|
+
Object.defineProperty(exports, "HybridEncryptionWrapper", { enumerable: true, get: function () { return index_6.HybridEncryptionWrapper; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cas-typescript-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
"test": "cargo test && npm run build && mocha -r ts-node/register ./test-ts/**/*.ts --timeout 20000 --recursive",
|
|
9
9
|
"node:test": "mocha -r ts-node/register ./test-ts/**/*.ts --timeout 20000 --recursive",
|
|
10
10
|
"rust:test": "cargo test",
|
|
11
|
-
"build": "
|
|
11
|
+
"build": "npm run build:rust && npm run build:node",
|
|
12
|
+
"build:rust": "napi build --release",
|
|
13
|
+
"build:node": "bash build-node.sh",
|
|
12
14
|
"prepare": "npm run build"
|
|
13
15
|
},
|
|
14
16
|
"repository": {
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +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
|
+
};
|
|
@@ -0,0 +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
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
24
|
+
}
|
package/src-ts/index.ts
CHANGED
|
@@ -8,19 +8,27 @@ import {
|
|
|
8
8
|
import { HasherFactory, HasherType, SHAWrapper } from "./hashers/index";
|
|
9
9
|
import { X25519Wrapper } from "./key_exchange/index";
|
|
10
10
|
import { AESWrapper } from "./symmetric/index";
|
|
11
|
-
import {
|
|
11
|
+
import { RsaKeyPairResult, RSAWrapper } from "./asymmetric/index";
|
|
12
|
+
import {
|
|
13
|
+
AesRsaHybridEncryptResult,
|
|
14
|
+
AESRSAHybridInitializer,
|
|
15
|
+
HybridEncryptionWrapper,
|
|
16
|
+
} from "./hybrid/index";
|
|
12
17
|
|
|
13
18
|
export {
|
|
19
|
+
AesRsaHybridEncryptResult,
|
|
20
|
+
AESRSAHybridInitializer,
|
|
21
|
+
AESWrapper,
|
|
14
22
|
Argon2Wrapper,
|
|
15
23
|
BCryptWrapper,
|
|
16
24
|
HasherFactory,
|
|
17
25
|
HasherType,
|
|
26
|
+
HybridEncryptionWrapper,
|
|
18
27
|
PasswordHasherFactory,
|
|
19
28
|
PasswordHasherType,
|
|
29
|
+
RsaKeyPairResult,
|
|
30
|
+
RSAWrapper,
|
|
20
31
|
ScryptWrapper,
|
|
21
32
|
SHAWrapper,
|
|
22
33
|
X25519Wrapper,
|
|
23
|
-
AESWrapper,
|
|
24
|
-
RSAWrapper,
|
|
25
|
-
RsaKeyPairResult
|
|
26
34
|
};
|
|
@@ -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
|
+
});
|
package/lib/cas_core_lib.dll
DELETED
|
Binary file
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { IHasherBase } from "./IHasherBase";
|
|
2
|
-
export declare class SHAWrapper implements IHasherBase {
|
|
3
|
-
hash_512(dataToHash: number[]): number[];
|
|
4
|
-
verify_512(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
5
|
-
hash_256(dataToHash: number[]): number[];
|
|
6
|
-
verify_256(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
7
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SHAWrapper = void 0;
|
|
4
|
-
const index_1 = require("../../index");
|
|
5
|
-
class SHAWrapper {
|
|
6
|
-
hash_512(dataToHash) {
|
|
7
|
-
if (!dataToHash || dataToHash.length === 0) {
|
|
8
|
-
throw new Error("You must provide an allocated array of data");
|
|
9
|
-
}
|
|
10
|
-
return (0, index_1.sha512)(dataToHash);
|
|
11
|
-
}
|
|
12
|
-
verify_512(dataToHash, dataToVerify) {
|
|
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 (0, index_1.sha512Verify)(dataToHash, dataToVerify);
|
|
20
|
-
}
|
|
21
|
-
hash_256(dataToHash) {
|
|
22
|
-
if (!dataToHash || dataToHash.length === 0) {
|
|
23
|
-
throw new Error("You must provide an allocated array of data");
|
|
24
|
-
}
|
|
25
|
-
return (0, index_1.sha256)(dataToHash);
|
|
26
|
-
}
|
|
27
|
-
verify_256(dataToHash, dataToVerify) {
|
|
28
|
-
if (!dataToHash || dataToHash.length === 0) {
|
|
29
|
-
throw new Error("You must provide an allocated array of data");
|
|
30
|
-
}
|
|
31
|
-
if (!dataToVerify || dataToVerify.length === 0) {
|
|
32
|
-
throw new Error("You must provide an allocated array of data to verify");
|
|
33
|
-
}
|
|
34
|
-
return (0, index_1.sha256Verify)(dataToHash, dataToVerify);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.SHAWrapper = SHAWrapper;
|
package/lib/libcas_core_lib.so
DELETED
|
Binary file
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const koffi_1 = __importDefault(require("koffi"));
|
|
7
|
-
const Argon2HashThreadResult = koffi_1.default.struct("Argon2HashThreadResult", {
|
|
8
|
-
passwords: 'char *',
|
|
9
|
-
length: 'int'
|
|
10
|
-
});
|
|
11
|
-
exports.default = Argon2HashThreadResult;
|