react-native-des-machine 0.1.0 → 1.0.0
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 +272 -49
- package/android/src/main/java/com/desmachine/DesMachineModule.kt +77 -68
- package/ios/DesMachine.h +0 -6
- package/ios/DesMachine.mm +120 -83
- package/lib/module/NativeDesMachine.js.map +1 -1
- package/lib/module/index.js +149 -11
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeDesMachine.d.ts +25 -3
- package/lib/typescript/src/NativeDesMachine.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +95 -5
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +27 -11
- package/src/NativeDesMachine.ts +26 -3
- package/src/index.ts +164 -13
|
@@ -10,9 +10,99 @@ interface OptionsList<T extends string> {
|
|
|
10
10
|
declare const modeOptions: OptionsList<ModeEncryptionType>[];
|
|
11
11
|
declare const paddingOptions: OptionsList<PaddingEncryptionType>[];
|
|
12
12
|
declare const formatOptions: OptionsList<OutputFormatType>[];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
/**
|
|
14
|
+
* DES Machine class for encryption and decryption.
|
|
15
|
+
* Supports multiple instances with different configurations.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // Create a machine with default settings
|
|
20
|
+
* const machine = new DesMachine({ key: 'mySecretKey123' });
|
|
21
|
+
*
|
|
22
|
+
* // Encrypt and decrypt
|
|
23
|
+
* const encrypted = machine.encrypt('Hello World');
|
|
24
|
+
* const decrypted = machine.decrypt(encrypted);
|
|
25
|
+
*
|
|
26
|
+
* // Create another machine with custom IV for CBC mode
|
|
27
|
+
* const cbcMachine = new DesMachine({
|
|
28
|
+
* key: 'anotherKey1',
|
|
29
|
+
* iv: '12345678', // 8 characters for DES
|
|
30
|
+
* mode: Mode.CBC,
|
|
31
|
+
* outputFormat: Format.HEX,
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare class DesMachine {
|
|
36
|
+
private params;
|
|
37
|
+
/**
|
|
38
|
+
* Create a new DES Machine instance.
|
|
39
|
+
* @param params - Configuration parameters
|
|
40
|
+
* @throws Error if key is missing or less than 8 characters
|
|
41
|
+
* @throws Error if iv is provided but not exactly 8 characters
|
|
42
|
+
*/
|
|
43
|
+
constructor(params: DesMachineParams);
|
|
44
|
+
/**
|
|
45
|
+
* Encrypt plaintext using DES algorithm.
|
|
46
|
+
* @param text - The plaintext to encrypt
|
|
47
|
+
* @returns Encrypted string in the configured output format
|
|
48
|
+
*/
|
|
49
|
+
encrypt(text: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* Decrypt ciphertext using DES algorithm.
|
|
52
|
+
* @param text - The encrypted string to decrypt
|
|
53
|
+
* @returns Decrypted plaintext
|
|
54
|
+
*/
|
|
55
|
+
decrypt(text: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* Get the current configuration parameters.
|
|
58
|
+
* @returns A copy of the current parameters (key and iv are masked)
|
|
59
|
+
*/
|
|
60
|
+
getParams(): Omit<DesMachineParams, 'key' | 'iv'> & {
|
|
61
|
+
key: string;
|
|
62
|
+
iv?: string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Update configuration parameters.
|
|
66
|
+
* @param params - New parameters to apply (key and iv cannot be changed)
|
|
67
|
+
*/
|
|
68
|
+
updateParams(params: Partial<Omit<DesMachineParams, 'key' | 'iv'>>): void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create a new DES Machine instance.
|
|
72
|
+
* @param params - Configuration parameters
|
|
73
|
+
* @returns A new DesMachine instance
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const machine = createDesMachine({ key: 'mySecretKey123' });
|
|
78
|
+
* const encrypted = machine.encrypt('Hello');
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
declare function createDesMachine(params: DesMachineParams): DesMachine;
|
|
82
|
+
/**
|
|
83
|
+
* Quick encrypt function for one-off encryption.
|
|
84
|
+
* @param params - Configuration parameters including key
|
|
85
|
+
* @param text - The plaintext to encrypt
|
|
86
|
+
* @returns Encrypted string
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const encrypted = encrypt({ key: 'mySecretKey123' }, 'Hello World');
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
declare function encrypt(params: DesMachineParams, text: string): string;
|
|
94
|
+
/**
|
|
95
|
+
* Quick decrypt function for one-off decryption.
|
|
96
|
+
* @param params - Configuration parameters including key
|
|
97
|
+
* @param text - The encrypted string to decrypt
|
|
98
|
+
* @returns Decrypted plaintext
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const decrypted = decrypt({ key: 'mySecretKey123' }, encryptedText);
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
declare function decrypt(params: DesMachineParams, text: string): string;
|
|
106
|
+
export { DesMachine, createDesMachine, encrypt, decrypt, Mode, Padding, Format, modeOptions, paddingOptions, formatOptions, };
|
|
107
|
+
export type { DesMachineParams, ModeEncryptionType, PaddingEncryptionType, OutputFormatType, };
|
|
18
108
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAyB,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,oBAAoB,CAAC;AAG5B,QAAA,MAAM,OAAO,EAAE,MAAM,CAAC,qBAAqB,EAAE,qBAAqB,CAKjE,CAAC;AAEF,QAAA,MAAM,IAAI,EAAE,MAAM,CAAC,kBAAkB,EAAE,kBAAkB,CAMxD,CAAC;AAEF,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,gBAAgB,EAAE,gBAAgB,CAGtD,CAAC;AAGF,UAAU,WAAW,CAAC,CAAC,SAAS,MAAM;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,CAAC,CAAC;CACV;AAED,QAAA,MAAM,WAAW,EAAE,WAAW,CAAC,kBAAkB,CAAC,EAMjD,CAAC;AAEF,QAAA,MAAM,cAAc,EAAE,WAAW,CAAC,qBAAqB,CAAC,EAKvD,CAAC;AAEF,QAAA,MAAM,aAAa,EAAE,WAAW,CAAC,gBAAgB,CAAC,EAGjD,CAAC;AASF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,cAAM,UAAU;IACd,OAAO,CAAC,MAAM,CAAmB;IAEjC;;;;;OAKG;gBACS,MAAM,EAAE,gBAAgB;IAoBpC;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI7B;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI7B;;;OAGG;IACH,SAAS,IAAI,IAAI,CAAC,gBAAgB,EAAE,KAAK,GAAG,IAAI,CAAC,GAAG;QAClD,GAAG,EAAE,MAAM,CAAC;QACZ,EAAE,CAAC,EAAE,MAAM,CAAC;KACb;IAQD;;;OAGG;IACH,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI;CAK1E;AAED;;;;;;;;;;GAUG;AACH,iBAAS,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,UAAU,CAE9D;AAED;;;;;;;;;;GAUG;AACH,iBAAS,OAAO,CAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAG/D;AAED;;;;;;;;;;GAUG;AACH,iBAAS,OAAO,CAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAG/D;AAED,OAAO,EAEL,UAAU,EACV,gBAAgB,EAEhB,OAAO,EACP,OAAO,EAEP,IAAI,EACJ,OAAO,EACP,MAAM,EAEN,WAAW,EACX,cAAc,EACd,aAAa,GACd,CAAC;AAEF,YAAY,EACV,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,GACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-des-machine",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "React Native
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "React Native DES encryption and decryption library with TurboModule support. Encrypt and decrypt text using DES algorithm with multiple cipher modes (ECB, CBC, CFB, OFB, CTR), padding schemes (PKCS7, ISO10126, Zero, None), and output formats (Base64, Hex) for iOS and Android.",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -17,9 +17,7 @@
|
|
|
17
17
|
"lib",
|
|
18
18
|
"android",
|
|
19
19
|
"ios",
|
|
20
|
-
"cpp",
|
|
21
20
|
"*.podspec",
|
|
22
|
-
"react-native.config.js",
|
|
23
21
|
"!ios/build",
|
|
24
22
|
"!android/build",
|
|
25
23
|
"!android/gradle",
|
|
@@ -32,7 +30,6 @@
|
|
|
32
30
|
"!**/.*"
|
|
33
31
|
],
|
|
34
32
|
"scripts": {
|
|
35
|
-
"example": "yarn workspace react-native-des-machine-example",
|
|
36
33
|
"clean": "del-cli lib",
|
|
37
34
|
"prepare": "bob build",
|
|
38
35
|
"typecheck": "tsc",
|
|
@@ -43,7 +40,31 @@
|
|
|
43
40
|
"keywords": [
|
|
44
41
|
"react-native",
|
|
45
42
|
"ios",
|
|
46
|
-
"android"
|
|
43
|
+
"android",
|
|
44
|
+
"des",
|
|
45
|
+
"encryption",
|
|
46
|
+
"decryption",
|
|
47
|
+
"crypto",
|
|
48
|
+
"cryptography",
|
|
49
|
+
"cipher",
|
|
50
|
+
"encrypt",
|
|
51
|
+
"decrypt",
|
|
52
|
+
"security",
|
|
53
|
+
"turbo-module",
|
|
54
|
+
"turbomodule",
|
|
55
|
+
"native-module",
|
|
56
|
+
"des-encryption",
|
|
57
|
+
"des-decryption",
|
|
58
|
+
"ecb",
|
|
59
|
+
"cbc",
|
|
60
|
+
"pkcs7",
|
|
61
|
+
"base64",
|
|
62
|
+
"hex",
|
|
63
|
+
"react-native-encryption",
|
|
64
|
+
"react-native-crypto",
|
|
65
|
+
"react-native-security",
|
|
66
|
+
"mobile-encryption",
|
|
67
|
+
"text-encryption"
|
|
47
68
|
],
|
|
48
69
|
"repository": {
|
|
49
70
|
"type": "git",
|
|
@@ -86,10 +107,6 @@
|
|
|
86
107
|
"react": "*",
|
|
87
108
|
"react-native": "*"
|
|
88
109
|
},
|
|
89
|
-
"workspaces": [
|
|
90
|
-
"example"
|
|
91
|
-
],
|
|
92
|
-
"packageManager": "yarn@4.11.0",
|
|
93
110
|
"react-native-builder-bob": {
|
|
94
111
|
"source": "src",
|
|
95
112
|
"output": "lib",
|
|
@@ -119,7 +136,6 @@
|
|
|
119
136
|
"jest": {
|
|
120
137
|
"preset": "react-native",
|
|
121
138
|
"modulePathIgnorePatterns": [
|
|
122
|
-
"<rootDir>/example/node_modules",
|
|
123
139
|
"<rootDir>/lib/"
|
|
124
140
|
]
|
|
125
141
|
},
|
package/src/NativeDesMachine.ts
CHANGED
|
@@ -5,16 +5,39 @@ export type PaddingEncryptionType = 'PKCS7' | 'ISO10126' | 'ZERO' | 'NONE';
|
|
|
5
5
|
export type OutputFormatType = 'BASE64' | 'HEX';
|
|
6
6
|
|
|
7
7
|
export interface DesMachineParams {
|
|
8
|
+
/**
|
|
9
|
+
* Encryption key (minimum 8 characters)
|
|
10
|
+
*/
|
|
8
11
|
key: string;
|
|
12
|
+
/**
|
|
13
|
+
* Initialization Vector for non-ECB modes (exactly 8 characters)
|
|
14
|
+
* If not provided, the first 8 bytes of the key will be used as IV
|
|
15
|
+
*/
|
|
16
|
+
iv?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Cipher mode (default: ECB)
|
|
19
|
+
*/
|
|
9
20
|
mode?: ModeEncryptionType;
|
|
21
|
+
/**
|
|
22
|
+
* Padding scheme (default: PKCS7)
|
|
23
|
+
*/
|
|
10
24
|
padding?: PaddingEncryptionType;
|
|
25
|
+
/**
|
|
26
|
+
* Output format (default: BASE64)
|
|
27
|
+
*/
|
|
11
28
|
outputFormat?: OutputFormatType;
|
|
12
29
|
}
|
|
13
30
|
|
|
14
31
|
export interface Spec extends TurboModule {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Encrypt text with provided params (stateless operation)
|
|
34
|
+
*/
|
|
35
|
+
encrypt(params: DesMachineParams, text: string): string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Decrypt text with provided params (stateless operation)
|
|
39
|
+
*/
|
|
40
|
+
decrypt(params: DesMachineParams, text: string): string;
|
|
18
41
|
}
|
|
19
42
|
|
|
20
43
|
export default TurboModuleRegistry.getEnforcing<Spec>('DesMachine');
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import NativeDesMachine, { type DesMachineParams } from './NativeDesMachine';
|
|
2
2
|
import type {
|
|
3
3
|
ModeEncryptionType,
|
|
4
4
|
PaddingEncryptionType,
|
|
5
5
|
OutputFormatType,
|
|
6
6
|
} from './NativeDesMachine';
|
|
7
7
|
|
|
8
|
+
// Constants
|
|
8
9
|
const Padding: Record<PaddingEncryptionType, PaddingEncryptionType> = {
|
|
9
10
|
PKCS7: 'PKCS7',
|
|
10
11
|
ISO10126: 'ISO10126',
|
|
@@ -25,6 +26,7 @@ const Format: Record<OutputFormatType, OutputFormatType> = {
|
|
|
25
26
|
HEX: 'HEX',
|
|
26
27
|
};
|
|
27
28
|
|
|
29
|
+
// Options for UI
|
|
28
30
|
interface OptionsList<T extends string> {
|
|
29
31
|
label: string;
|
|
30
32
|
value: T;
|
|
@@ -50,26 +52,175 @@ const formatOptions: OptionsList<OutputFormatType>[] = [
|
|
|
50
52
|
{ label: 'Hexadecimal', value: Format.HEX },
|
|
51
53
|
];
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
// Default parameters
|
|
56
|
+
const defaultParams: Omit<DesMachineParams, 'key'> = {
|
|
54
57
|
mode: Mode.ECB,
|
|
55
58
|
padding: Padding.PKCS7,
|
|
56
59
|
outputFormat: Format.BASE64,
|
|
57
60
|
};
|
|
58
61
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
/**
|
|
63
|
+
* DES Machine class for encryption and decryption.
|
|
64
|
+
* Supports multiple instances with different configurations.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* // Create a machine with default settings
|
|
69
|
+
* const machine = new DesMachine({ key: 'mySecretKey123' });
|
|
70
|
+
*
|
|
71
|
+
* // Encrypt and decrypt
|
|
72
|
+
* const encrypted = machine.encrypt('Hello World');
|
|
73
|
+
* const decrypted = machine.decrypt(encrypted);
|
|
74
|
+
*
|
|
75
|
+
* // Create another machine with custom IV for CBC mode
|
|
76
|
+
* const cbcMachine = new DesMachine({
|
|
77
|
+
* key: 'anotherKey1',
|
|
78
|
+
* iv: '12345678', // 8 characters for DES
|
|
79
|
+
* mode: Mode.CBC,
|
|
80
|
+
* outputFormat: Format.HEX,
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
class DesMachine {
|
|
85
|
+
private params: DesMachineParams;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Create a new DES Machine instance.
|
|
89
|
+
* @param params - Configuration parameters
|
|
90
|
+
* @throws Error if key is missing or less than 8 characters
|
|
91
|
+
* @throws Error if iv is provided but not exactly 8 characters
|
|
92
|
+
*/
|
|
93
|
+
constructor(params: DesMachineParams) {
|
|
94
|
+
if (!params.key) {
|
|
95
|
+
throw new Error('DesMachine: key is required');
|
|
96
|
+
}
|
|
97
|
+
if (params.key.length < 8) {
|
|
98
|
+
throw new Error('DesMachine: key must be at least 8 characters long');
|
|
99
|
+
}
|
|
100
|
+
if (params.iv !== undefined && params.iv.length !== 8) {
|
|
101
|
+
throw new Error('DesMachine: iv must be exactly 8 characters long');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
this.params = {
|
|
105
|
+
key: params.key,
|
|
106
|
+
iv: params.iv,
|
|
107
|
+
mode: params.mode ?? defaultParams.mode!,
|
|
108
|
+
padding: params.padding ?? defaultParams.padding!,
|
|
109
|
+
outputFormat: params.outputFormat ?? defaultParams.outputFormat!,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Encrypt plaintext using DES algorithm.
|
|
115
|
+
* @param text - The plaintext to encrypt
|
|
116
|
+
* @returns Encrypted string in the configured output format
|
|
117
|
+
*/
|
|
118
|
+
encrypt(text: string): string {
|
|
119
|
+
return NativeDesMachine.encrypt(this.params, text);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Decrypt ciphertext using DES algorithm.
|
|
124
|
+
* @param text - The encrypted string to decrypt
|
|
125
|
+
* @returns Decrypted plaintext
|
|
126
|
+
*/
|
|
127
|
+
decrypt(text: string): string {
|
|
128
|
+
return NativeDesMachine.decrypt(this.params, text);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Get the current configuration parameters.
|
|
133
|
+
* @returns A copy of the current parameters (key and iv are masked)
|
|
134
|
+
*/
|
|
135
|
+
getParams(): Omit<DesMachineParams, 'key' | 'iv'> & {
|
|
136
|
+
key: string;
|
|
137
|
+
iv?: string;
|
|
138
|
+
} {
|
|
139
|
+
return {
|
|
140
|
+
...this.params,
|
|
141
|
+
key: this.params.key.substring(0, 2) + '***',
|
|
142
|
+
iv: this.params.iv ? this.params.iv.substring(0, 2) + '***' : undefined,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Update configuration parameters.
|
|
148
|
+
* @param params - New parameters to apply (key and iv cannot be changed)
|
|
149
|
+
*/
|
|
150
|
+
updateParams(params: Partial<Omit<DesMachineParams, 'key' | 'iv'>>): void {
|
|
151
|
+
if (params.mode) this.params.mode = params.mode;
|
|
152
|
+
if (params.padding) this.params.padding = params.padding;
|
|
153
|
+
if (params.outputFormat) this.params.outputFormat = params.outputFormat;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Create a new DES Machine instance.
|
|
159
|
+
* @param params - Configuration parameters
|
|
160
|
+
* @returns A new DesMachine instance
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const machine = createDesMachine({ key: 'mySecretKey123' });
|
|
165
|
+
* const encrypted = machine.encrypt('Hello');
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
function createDesMachine(params: DesMachineParams): DesMachine {
|
|
169
|
+
return new DesMachine(params);
|
|
64
170
|
}
|
|
65
171
|
|
|
66
|
-
|
|
67
|
-
|
|
172
|
+
/**
|
|
173
|
+
* Quick encrypt function for one-off encryption.
|
|
174
|
+
* @param params - Configuration parameters including key
|
|
175
|
+
* @param text - The plaintext to encrypt
|
|
176
|
+
* @returns Encrypted string
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* const encrypted = encrypt({ key: 'mySecretKey123' }, 'Hello World');
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
function encrypt(params: DesMachineParams, text: string): string {
|
|
184
|
+
const machine = new DesMachine(params);
|
|
185
|
+
return machine.encrypt(text);
|
|
68
186
|
}
|
|
69
187
|
|
|
70
|
-
|
|
71
|
-
|
|
188
|
+
/**
|
|
189
|
+
* Quick decrypt function for one-off decryption.
|
|
190
|
+
* @param params - Configuration parameters including key
|
|
191
|
+
* @param text - The encrypted string to decrypt
|
|
192
|
+
* @returns Decrypted plaintext
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* const decrypted = decrypt({ key: 'mySecretKey123' }, encryptedText);
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
function decrypt(params: DesMachineParams, text: string): string {
|
|
200
|
+
const machine = new DesMachine(params);
|
|
201
|
+
return machine.decrypt(text);
|
|
72
202
|
}
|
|
73
203
|
|
|
74
|
-
export {
|
|
75
|
-
|
|
204
|
+
export {
|
|
205
|
+
// Main class
|
|
206
|
+
DesMachine,
|
|
207
|
+
createDesMachine,
|
|
208
|
+
// Quick functions
|
|
209
|
+
encrypt,
|
|
210
|
+
decrypt,
|
|
211
|
+
// Constants
|
|
212
|
+
Mode,
|
|
213
|
+
Padding,
|
|
214
|
+
Format,
|
|
215
|
+
// Options for UI
|
|
216
|
+
modeOptions,
|
|
217
|
+
paddingOptions,
|
|
218
|
+
formatOptions,
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
export type {
|
|
222
|
+
DesMachineParams,
|
|
223
|
+
ModeEncryptionType,
|
|
224
|
+
PaddingEncryptionType,
|
|
225
|
+
OutputFormatType,
|
|
226
|
+
};
|