1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | declare class NodeRSA {
|
12 | |
13 |
|
14 |
|
15 | constructor(key?: NodeRSA.KeyBits);
|
16 |
|
17 | /**
|
18 | * Load key from string/buffer/components.
|
19 | */
|
20 | constructor(key: NodeRSA.Key, format?: NodeRSA.Format, options?: NodeRSA.Options);
|
21 |
|
22 | /**
|
23 | * Set and validate options for key instance.
|
24 | */
|
25 | setOptions(options: NodeRSA.Options): void;
|
26 |
|
27 | /**
|
28 | * @param bits Key size in bits. 2048 by default.
|
29 | * @param exponent public exponent. 65537 by default.
|
30 | */
|
31 | generateKeyPair(bits?: number, exponent?: number): NodeRSA;
|
32 |
|
33 | /**
|
34 | * Import key from PEM string, PEM/DER Buffer or components.
|
35 | */
|
36 | importKey(key: NodeRSA.Key, format?: NodeRSA.Format): NodeRSA;
|
37 |
|
38 | /**
|
39 | * Export key to PEM string, PEM/DER Buffer or components.
|
40 | */
|
41 | exportKey(format?: NodeRSA.FormatPem): string;
|
42 | exportKey(format: NodeRSA.FormatDer): Buffer;
|
43 | exportKey(format: NodeRSA.FormatComponentsPrivate): NodeRSA.KeyComponentsPrivate;
|
44 | exportKey(format: NodeRSA.FormatComponentsPublic): NodeRSA.KeyComponentsPublic;
|
45 |
|
46 | isPrivate(): boolean;
|
47 |
|
48 | /**
|
49 | * @param strict if true method will return false if key pair have private exponent. Default false.
|
50 | */
|
51 | isPublic(strict?: boolean): boolean;
|
52 |
|
53 | /**
|
54 | * Return true if key pair doesn't have any data.
|
55 | */
|
56 | isEmpty(): boolean;
|
57 |
|
58 | /**
|
59 | * Return key size in bits.
|
60 | */
|
61 | getKeySize(): number;
|
62 |
|
63 | /**
|
64 | * Return max data size for encrypt in bytes.
|
65 | */
|
66 | getMaxMessageSize(): number;
|
67 |
|
68 | encrypt(data: NodeRSA.Data, encoding?: 'buffer'): Buffer;
|
69 | encrypt(data: NodeRSA.Data, encoding: NodeRSA.Encoding): string;
|
70 | encrypt(data: Buffer, encoding: 'buffer', sourceEncoding?: NodeRSA.Encoding): Buffer;
|
71 | encrypt(data: Buffer, encoding: NodeRSA.Encoding, sourceEncoding?: NodeRSA.Encoding): string;
|
72 |
|
73 | encryptPrivate(data: NodeRSA.Data, encoding?: 'buffer'): Buffer;
|
74 | encryptPrivate(data: NodeRSA.Data, encoding: NodeRSA.Encoding): string;
|
75 | encryptPrivate(data: Buffer, encoding: 'buffer', sourceEncoding?: NodeRSA.Encoding): Buffer;
|
76 | encryptPrivate(data: Buffer, encoding: NodeRSA.Encoding, sourceEncoding?: NodeRSA.Encoding): string;
|
77 |
|
78 | decrypt(data: Buffer | string, encoding?: 'buffer'): Buffer;
|
79 | decrypt(data: Buffer | string, encoding: NodeRSA.Encoding): string;
|
80 | decrypt<T extends object>(data: Buffer | string, encoding: 'json'): T;
|
81 |
|
82 | decryptPublic(data: Buffer | string, encoding?: 'buffer'): Buffer;
|
83 | decryptPublic(data: Buffer | string, encoding: NodeRSA.Encoding): string;
|
84 | decryptPublic<T extends object>(data: Buffer | string, encoding: 'json'): T;
|
85 |
|
86 | sign(data: NodeRSA.Data, encoding?: 'buffer'): Buffer;
|
87 | sign(data: NodeRSA.Data, encoding: NodeRSA.Encoding): string;
|
88 | sign(data: Buffer, encoding: 'buffer', sourceEncoding?: NodeRSA.Encoding): Buffer;
|
89 | sign(data: Buffer, encoding: NodeRSA.Encoding, sourceEncoding?: NodeRSA.Encoding): string;
|
90 |
|
91 | verify(data: NodeRSA.Data, signature: Buffer): boolean;
|
92 | verify(data: Buffer, signature: Buffer, sourceEncoding?: NodeRSA.Encoding): boolean;
|
93 | verify(
|
94 | data: Buffer,
|
95 | signature: string,
|
96 | sourceEncoding: NodeRSA.Encoding,
|
97 | signatureEncoding: NodeRSA.Encoding,
|
98 | ): boolean;
|
99 | verify(
|
100 | data: NodeRSA.Data,
|
101 | signature: string,
|
102 | sourceEncoding: undefined,
|
103 | signatureEncoding: NodeRSA.Encoding,
|
104 | ): boolean;
|
105 | }
|
106 |
|
107 | declare namespace NodeRSA {
|
108 | type Key = string | Buffer | KeyComponentsPrivate | KeyComponentsPublic;
|
109 | type Data = string | object | any[];
|
110 |
|
111 | type FormatPem =
|
112 | | 'private'
|
113 | | 'public'
|
114 | | 'pkcs1'
|
115 | | 'pkcs1-pem'
|
116 | | 'pkcs1-private'
|
117 | | 'pkcs1-private-pem'
|
118 | | 'pkcs1-public'
|
119 | | 'pkcs1-public-pem'
|
120 | | 'pkcs8'
|
121 | | 'pkcs8-pem'
|
122 | | 'pkcs8-private'
|
123 | | 'pkcs8-private-pem'
|
124 | | 'pkcs8-public'
|
125 | | 'pkcs8-public-pem'
|
126 | | 'openssh-public'
|
127 | | 'openssh-private';
|
128 | type FormatDer =
|
129 | | 'pkcs1-der'
|
130 | | 'pkcs1-private-der'
|
131 | | 'pkcs1-public-der'
|
132 | | 'pkcs8-der'
|
133 | | 'pkcs8-private-der'
|
134 | | 'pkcs8-public-der';
|
135 | type FormatComponentsPrivate =
|
136 | | 'components'
|
137 | | 'components-pem'
|
138 | | 'components-der'
|
139 | | 'components-private'
|
140 | | 'components-private-pem'
|
141 | | 'components-private-der';
|
142 | type FormatComponentsPublic = 'components-public' | 'components-public-pem' | 'components-public-der';
|
143 | type Format = FormatPem | FormatDer | FormatComponentsPrivate | FormatComponentsPublic;
|
144 |
|
145 | type EncryptionScheme = 'pkcs1_oaep' | 'pkcs1';
|
146 |
|
147 | type HashingAlgorithm = 'ripemd160' | 'md4' | 'md5' | 'sha1' | 'sha224' | 'sha256' | 'sha384' | 'sha512';
|
148 |
|
149 | type SigningScheme = 'pkcs1' | 'pss';
|
150 |
|
151 | type SigningSchemeHash =
|
152 | | 'pkcs1-ripemd160'
|
153 | | 'pkcs1-md4'
|
154 | | 'pkcs1-md5'
|
155 | | 'pkcs1-sha'
|
156 | | 'pkcs1-sha1'
|
157 | | 'pkcs1-sha224'
|
158 | | 'pkcs1-sha256'
|
159 | | 'pkcs1-sha384'
|
160 | | 'pkcs1-sha512'
|
161 | | 'pss-ripemd160'
|
162 | | 'pss-md4'
|
163 | | 'pss-md5'
|
164 | | 'pss-sha'
|
165 | | 'pss-sha1'
|
166 | | 'pss-sha224'
|
167 | | 'pss-sha256'
|
168 | | 'pss-sha384'
|
169 | | 'pss-sha512';
|
170 |
|
171 | type Encoding = 'ascii' | 'utf8' | 'utf16le' | 'ucs2' | 'latin1' | 'base64' | 'hex' | 'binary' | 'buffer';
|
172 |
|
173 | interface KeyComponentsPrivate {
|
174 | n: Buffer;
|
175 | e: Buffer | number;
|
176 | d: Buffer;
|
177 | p: Buffer;
|
178 | q: Buffer;
|
179 | dmp1: Buffer;
|
180 | dmq1: Buffer;
|
181 | coeff: Buffer;
|
182 | }
|
183 |
|
184 | interface KeyComponentsPublic {
|
185 | n: Buffer;
|
186 | e: Buffer | number;
|
187 | }
|
188 |
|
189 | interface KeyBits {
|
190 | |
191 |
|
192 |
|
193 | b: number;
|
194 | }
|
195 |
|
196 | interface AdvancedEncryptionSchemePKCS1 {
|
197 | scheme: 'pkcs1';
|
198 | padding: number;
|
199 | }
|
200 |
|
201 | interface AdvancedEncryptionSchemePKCS1OAEP {
|
202 | scheme: 'pkcs1_oaep';
|
203 | hash: HashingAlgorithm;
|
204 |
|
205 | |
206 |
|
207 |
|
208 | mgf?(data: Buffer, length: number, hash: HashingAlgorithm): Buffer;
|
209 | }
|
210 |
|
211 | type AdvancedEncryptionScheme = AdvancedEncryptionSchemePKCS1 | AdvancedEncryptionSchemePKCS1OAEP;
|
212 |
|
213 | interface AdvancedSigningSchemePSS {
|
214 | scheme: 'pss';
|
215 | hash: HashingAlgorithm;
|
216 | saltLength: number;
|
217 | }
|
218 |
|
219 | interface AdvancedSigningSchemePKCS1 {
|
220 | scheme: 'pkcs1';
|
221 | hash: HashingAlgorithm;
|
222 | }
|
223 |
|
224 | type AdvancedSigningScheme = AdvancedSigningSchemePSS | AdvancedSigningSchemePKCS1;
|
225 |
|
226 | interface Options {
|
227 | |
228 |
|
229 |
|
230 | environment?: 'browser' | 'node' | undefined;
|
231 |
|
232 | |
233 |
|
234 |
|
235 | encryptionScheme?: EncryptionScheme | AdvancedEncryptionScheme | undefined;
|
236 |
|
237 | |
238 |
|
239 |
|
240 | signingScheme?: SigningScheme | SigningSchemeHash | AdvancedSigningScheme | undefined;
|
241 | }
|
242 | }
|
243 |
|
244 | export = NodeRSA;
|