• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import type { AsyncCallback, Callback } from './@ohos.base';
17
18/**
19 * Provides a set of encryption and decryption algorithm library framework, shields the underlying differences,
20 * encapsulate the relevant algorithm library, and provides a unified functional interface upward.
21 *
22 * @namespace cryptoFramework
23 * @syscap SystemCapability.Security.CryptoFramework
24 * @since 9
25 */
26declare namespace cryptoFramework {
27  /**
28   * Enum for result code.
29   *
30   * @enum { number }
31   * @syscap SystemCapability.Security.CryptoFramework
32   * @since 9
33   */
34  enum Result {
35    /**
36     * Indicates that input parameters is invalid.
37     *
38     * @syscap SystemCapability.Security.CryptoFramework
39     * @since 9
40     */
41    INVALID_PARAMS = 401,
42
43    /**
44     * Indicates that function or algorithm is not supported.
45     *
46     * @syscap SystemCapability.Security.CryptoFramework
47     * @since 9
48     */
49    NOT_SUPPORT = 801,
50
51    /**
52     * Indicates the memory error.
53     *
54     * @syscap SystemCapability.Security.CryptoFramework
55     * @since 9
56     */
57    ERR_OUT_OF_MEMORY = 17620001,
58
59    /**
60     * Indicates that runtime error.
61     *
62     * @syscap SystemCapability.Security.CryptoFramework
63     * @since 9
64     */
65    ERR_RUNTIME_ERROR = 17620002,
66
67    /**
68     * Indicates that crypto operation error.
69     *
70     * @syscap SystemCapability.Security.CryptoFramework
71     * @since 9
72     */
73    ERR_CRYPTO_OPERATION = 17630001
74  }
75
76  /**
77   * Provides the data blob type.
78   *
79   * @typedef DataBlob
80   * @syscap SystemCapability.Security.CryptoFramework
81   * @since 9
82   */
83  interface DataBlob {
84    /**
85     * Indicates the content of data blob.
86     *
87     * @type { Uint8Array }
88     * @syscap SystemCapability.Security.CryptoFramework
89     * @since 9
90     */
91    data: Uint8Array;
92  }
93
94  /**
95   * Provides the ParamsSpec type, including the algorithm name.
96   *
97   * @typedef ParamsSpec
98   * @syscap SystemCapability.Security.CryptoFramework
99   * @since 9
100   */
101  interface ParamsSpec {
102    /**
103     * Indicates the algorithm name. Should be set before initialization of a cipher object.
104     *
105     * @type { string }
106     * @syscap SystemCapability.Security.CryptoFramework
107     * @since 9
108     */
109    algName: string;
110  }
111
112  /**
113   * Provides the IvParamsSpec type, including the parameter iv.
114   *
115   * @typedef IvParamsSpec
116   * @syscap SystemCapability.Security.CryptoFramework
117   * @since 9
118   */
119  interface IvParamsSpec extends ParamsSpec {
120    /**
121     * Indicates the algorithm parameters such as iv.
122     *
123     * @type { DataBlob }
124     * @syscap SystemCapability.Security.CryptoFramework
125     * @since 9
126     */
127    iv: DataBlob;
128  }
129
130  /**
131   * Provides the GcmParamsSpec type, including the parameter iv, aad and authTag.
132   *
133   * @typedef GcmParamsSpec
134   * @syscap SystemCapability.Security.CryptoFramework
135   * @since 9
136   */
137  interface GcmParamsSpec extends ParamsSpec {
138    /**
139     * Indicates the GCM algorithm parameters such as iv.
140     *
141     * @type { DataBlob }
142     * @syscap SystemCapability.Security.CryptoFramework
143     * @since 9
144     */
145    iv: DataBlob;
146
147    /**
148     * Indicates the additional Authenticated Data in GCM mode.
149     *
150     * @type { DataBlob }
151     * @syscap SystemCapability.Security.CryptoFramework
152     * @since 9
153     */
154    aad: DataBlob;
155
156    /**
157     * Indicates the output tag from the encryption operation. The tag is used for integrity check.
158     *
159     * @type { DataBlob }
160     * @syscap SystemCapability.Security.CryptoFramework
161     * @since 9
162     */
163    authTag: DataBlob;
164  }
165
166  /**
167   * Provides the CcmParamsSpec type, including the parameter iv, aad and authTag.
168   *
169   * @typedef CcmParamsSpec
170   * @syscap SystemCapability.Security.CryptoFramework
171   * @since 9
172   */
173  interface CcmParamsSpec extends ParamsSpec {
174    /**
175     * Indicates the GCM algorithm parameters such as IV.
176     *
177     * @type { DataBlob }
178     * @syscap SystemCapability.Security.CryptoFramework
179     * @since 9
180     */
181    iv: DataBlob;
182
183    /**
184     * Indicates the Additional Authenticated Data in CCM mode.
185     *
186     * @type { DataBlob }
187     * @syscap SystemCapability.Security.CryptoFramework
188     * @since 9
189     */
190    aad: DataBlob;
191
192    /**
193     * Indicates the output tag from the encryption operation. The tag is used for integrity check.
194     *
195     * @type { DataBlob }
196     * @syscap SystemCapability.Security.CryptoFramework
197     * @since 9
198     */
199    authTag: DataBlob;
200  }
201
202  /**
203   * Enum for obtain the crypto operation.
204   *
205   * @enum { number }
206   * @syscap SystemCapability.Security.CryptoFramework
207   * @since 9
208   */
209  enum CryptoMode {
210    /**
211     * The value of encryption operation for AES, 3DES and RSA.
212     *
213     * @syscap SystemCapability.Security.CryptoFramework
214     * @since 9
215     */
216    ENCRYPT_MODE = 0,
217
218    /**
219     * The value of decryption operation for AES, 3DES and RSA.
220     *
221     * @syscap SystemCapability.Security.CryptoFramework
222     * @since 9
223     */
224    DECRYPT_MODE = 1
225  }
226
227  /**
228   * Provides the Key type, which is the common parent class of keys.
229   *
230   * @typedef Key
231   * @syscap SystemCapability.Security.CryptoFramework
232   * @since 9
233   */
234  interface Key {
235    /**
236     * Encode the key object to binary data.
237     *
238     * @returns { DataBlob } the binary data of the key object.
239     * @throws { BusinessError } 801 - this operation is not supported.
240     * @throws { BusinessError } 17620001 - memory error.
241     * @throws { BusinessError } 17630001 - crypto operation error.
242     * @syscap SystemCapability.Security.CryptoFramework
243     * @since 9
244     */
245    getEncoded(): DataBlob;
246
247    /**
248     * Indicates the format of the key object.
249     *
250     * @type { string }
251     * @readonly
252     * @syscap SystemCapability.Security.CryptoFramework
253     * @since 9
254     */
255    readonly format: string;
256
257    /**
258     * Indicates the algorithm name of the key object.
259     *
260     * @type { string }
261     * @readonly
262     * @syscap SystemCapability.Security.CryptoFramework
263     * @since 9
264     */
265    readonly algName: string;
266  }
267
268  /**
269   * Provides the SymKey type, which is used for symmetric cryptography.
270   *
271   * @typedef SymKey
272   * @syscap SystemCapability.Security.CryptoFramework
273   * @since 9
274   */
275  interface SymKey extends Key {
276    /**
277     * Reset the key data to zero in the memory.
278     *
279     * @syscap SystemCapability.Security.CryptoFramework
280     * @since 9
281     */
282    clearMem(): void;
283  }
284
285  /**
286   * Provides the private key type.
287   *
288   * @typedef PriKey
289   * @syscap SystemCapability.Security.CryptoFramework
290   * @since 9
291   */
292  interface PriKey extends Key {
293    /**
294     * Clear memory of private key.
295     *
296     * @syscap SystemCapability.Security.CryptoFramework
297     * @since 9
298     */
299    clearMem(): void;
300
301    /**
302     * Get the specified parameter of the private key.
303     *
304     * @param { AsyKeySpecItem } itemType - indicates the specified parameters type.
305     * @returns { bigint | string | number } the specified parameters value.
306     * @throws { BusinessError } 401 - invalid parameters.
307     * @throws { BusinessError } 17620001 - memory error.
308     * @throws { BusinessError } 17630001 - crypto operation error.
309     * @syscap SystemCapability.Security.CryptoFramework
310     * @since 10
311     */
312    getAsyKeySpec(itemType: AsyKeySpecItem): bigint | string | number;
313  }
314
315  /**
316   * Provides the public key interface for asymmetric keys.
317   *
318   * @typedef PubKey
319   * @syscap SystemCapability.Security.CryptoFramework
320   * @since 9
321   */
322  interface PubKey extends Key {
323    /**
324     * Get the specified parameter of the public key.
325     *
326     * @param { AsyKeySpecItem } itemType - indicates the specified parameters type.
327     * @returns { bigint | string | number } the specified parameters value.
328     * @throws { BusinessError } 401 - invalid parameters.
329     * @throws { BusinessError } 17620001 - memory error.
330     * @throws { BusinessError } 17630001 - crypto operation error.
331     * @syscap SystemCapability.Security.CryptoFramework
332     * @since 10
333     */
334    getAsyKeySpec(itemType: AsyKeySpecItem): bigint | string | number;
335  }
336
337  /**
338   * Provides the keypair interface for asymmetric keys. A keyPair object contains both private key and public key.
339   *
340   * @typedef KeyPair
341   * @syscap SystemCapability.Security.CryptoFramework
342   * @since 9
343   */
344  interface KeyPair {
345    /**
346     * KeyPair's private key.
347     *
348     * @type { PriKey }
349     * @readonly
350     * @syscap SystemCapability.Security.CryptoFramework
351     * @since 9
352     */
353    readonly priKey: PriKey;
354
355    /**
356     * KeyPair's public key.
357     *
358     * @type { PubKey }
359     * @readonly
360     * @syscap SystemCapability.Security.CryptoFramework
361     * @since 9
362     */
363    readonly pubKey: PubKey;
364  }
365
366  /**
367   * Provides the random interface.
368   *
369   * @typedef Random
370   * @syscap SystemCapability.Security.CryptoFramework
371   * @since 9
372   */
373  interface Random {
374    /**
375     * Generate random DataBlob by given length.
376     *
377     * @param { number } len - indicates the length of random DataBlob.
378     * @param { AsyncCallback<DataBlob> } callback - the callback used to return random DataBlob.
379     * @throws { BusinessError } 401 - invalid parameters.
380     * @throws { BusinessError } 17620001 - memory error.
381     * @throws { BusinessError } 17630001 - crypto operation error.
382     * @syscap SystemCapability.Security.CryptoFramework
383     * @since 9
384     */
385    generateRandom(len: number, callback: AsyncCallback<DataBlob>): void;
386
387    /**
388     * Generate random DataBlob by given length.
389     *
390     * @param { number } len - indicates the length of random DataBlob.
391     * @returns { Promise<DataBlob> } the promise used to return the generated random blob.
392     * @throws { BusinessError } 401 - invalid parameters.
393     * @throws { BusinessError } 17620001 - memory error.
394     * @throws { BusinessError } 17630001 - crypto operation error.
395     * @syscap SystemCapability.Security.CryptoFramework
396     * @since 9
397     */
398    generateRandom(len: number): Promise<DataBlob>;
399
400    /**
401     * Generate random DataBlob by given length synchronously.
402     *
403     * @param { number } len - indicates the length of random DataBlob.
404     * @returns { DataBlob } return the generated random blob.
405     * @throws { BusinessError } 401 - invalid parameters.
406     * @throws { BusinessError } 17620001 - memory error.
407     * @throws { BusinessError } 17630001 - crypto operation error.
408     * @syscap SystemCapability.Security.CryptoFramework
409     * @since 10
410     */
411    generateRandomSync(len: number): DataBlob;
412
413    /**
414     * Set seed by given DataBlob.
415     *
416     * @param { DataBlob } seed - indicates the seed DataBlob.
417     * @throws { BusinessError } 17620001 - memory error.
418     * @syscap SystemCapability.Security.CryptoFramework
419     * @since 9
420     */
421    setSeed(seed: DataBlob): void;
422
423    /**
424     * Indicates the random generation algorithm name.
425     *
426     * @type { string }
427     * @readonly
428     * @syscap SystemCapability.Security.CryptoFramework
429     * @since 10
430     */
431    readonly algName: string;
432  }
433
434  /**
435   * Create a random generator instance.
436   *
437   * @returns { Random } returns the created rand instance.
438   * @throws { BusinessError } 17620001 - memory error.
439   * @syscap SystemCapability.Security.CryptoFramework
440   * @since 9
441   */
442  function createRandom(): Random;
443
444  /**
445   * The AsyKeyGenerator provides the ability to generate or convert keyPair.
446   *
447   * @typedef AsyKeyGenerator
448   * @syscap SystemCapability.Security.CryptoFramework
449   * @since 9
450   */
451  interface AsyKeyGenerator {
452    /**
453     * Used to generate asymmetric keypair.
454     *
455     * @param { AsyncCallback<KeyPair> } callback - the callback used to return keypair.
456     * @throws { BusinessError } 401 - invalid parameters.
457     * @throws { BusinessError } 17620001 - memory error.
458     * @throws { BusinessError } 17630001 - crypto operation error.
459     * @syscap SystemCapability.Security.CryptoFramework
460     * @since 9
461     */
462    generateKeyPair(callback: AsyncCallback<KeyPair>): void;
463
464    /**
465     * Used to generate asymmetric keypair.
466     *
467     * @returns { Promise<KeyPair> } the promise used to return keypair.
468     * @throws { BusinessError } 401 - invalid parameters.
469     * @throws { BusinessError } 17620001 - memory error.
470     * @throws { BusinessError } 17630001 - crypto operation error.
471     * @syscap SystemCapability.Security.CryptoFramework
472     * @since 9
473     */
474    generateKeyPair(): Promise<KeyPair>;
475
476    /**
477     * Used to convert asymmetric key data to keypair object.
478     *
479     * @param { DataBlob } pubKey - the public key data blob.
480     * @param { DataBlob } priKey - the private key data blob.
481     * @param { AsyncCallback<KeyPair> } callback - the callback used to return keypair.
482     * @throws { BusinessError } 401 - invalid parameters.
483     * @throws { BusinessError } 17620001 - memory error.
484     * @throws { BusinessError } 17630001 - crypto operation error.
485     * @syscap SystemCapability.Security.CryptoFramework
486     * @since 9
487     */
488    convertKey(pubKey: DataBlob, priKey: DataBlob, callback: AsyncCallback<KeyPair>): void;
489
490    /**
491     * Used to convert asymmetric key data to keypair object.
492     *
493     * @param { DataBlob | null } pubKey - the public key data blob.
494     * @param { DataBlob | null } priKey - the private key data blob.
495     * @param { AsyncCallback<KeyPair> } callback - the callback used to return keypair.
496     * @throws { BusinessError } 401 - invalid parameters.
497     * @throws { BusinessError } 17620001 - memory error.
498     * @throws { BusinessError } 17630001 - crypto operation error.
499     * @syscap SystemCapability.Security.CryptoFramework
500     * @since 10
501     */
502    convertKey(pubKey: DataBlob | null, priKey: DataBlob | null, callback: AsyncCallback<KeyPair>): void;
503
504    /**
505     * Used to convert asymmetric key data to keypair object.
506     *
507     * @param { DataBlob } pubKey - the public key data blob.
508     * @param { DataBlob } priKey - the private key data blob.
509     * @returns { Promise<KeyPair> } the promise used to return keypair.
510     * @throws { BusinessError } 401 - invalid parameters.
511     * @throws { BusinessError } 17620001 - memory error.
512     * @throws { BusinessError } 17630001 - crypto operation error.
513     * @syscap SystemCapability.Security.CryptoFramework
514     * @since 9
515     */
516    convertKey(pubKey: DataBlob, priKey: DataBlob): Promise<KeyPair>;
517
518    /**
519     * Used to convert asymmetric key data to keypair object.
520     *
521     * @param { DataBlob | null } pubKey - the public key data blob.
522     * @param { DataBlob | null } priKey - the private key data blob.
523     * @returns { Promise<KeyPair> } the promise used to return keypair.
524     * @throws { BusinessError } 401 - invalid parameters.
525     * @throws { BusinessError } 17620001 - memory error.
526     * @throws { BusinessError } 17630001 - crypto operation error.
527     * @syscap SystemCapability.Security.CryptoFramework
528     * @since 10
529     */
530    convertKey(pubKey: DataBlob | null, priKey: DataBlob | null): Promise<KeyPair>;
531
532    /**
533     * The algName of the AsyKeyGenerator.
534     *
535     * @type { string }
536     * @readonly
537     * @syscap SystemCapability.Security.CryptoFramework
538     * @since 9
539     */
540    readonly algName: string;
541  }
542
543  /**
544   * Provides the SymKeyGenerator type, which is used for generating symmetric key.
545   *
546   * @typedef SymKeyGenerator
547   * @syscap SystemCapability.Security.CryptoFramework
548   * @since 9
549   */
550  interface SymKeyGenerator {
551    /**
552     * Generate a symmetric key object randomly.
553     *
554     * @param { AsyncCallback<SymKey> } callback - the callback of generateSymKey.
555     * @throws { BusinessError } 17620001 - memory error.
556     * @syscap SystemCapability.Security.CryptoFramework
557     * @since 9
558     */
559    generateSymKey(callback: AsyncCallback<SymKey>): void;
560
561    /**
562     * Generate a symmetric key object randomly.
563     *
564     * @returns { Promise<SymKey> } the promise returned by the function.
565     * @throws { BusinessError } 17620001 - memory error.
566     * @syscap SystemCapability.Security.CryptoFramework
567     * @since 9
568     */
569    generateSymKey(): Promise<SymKey>;
570
571    /**
572     * Generate a symmetric key object according to the provided binary key data.
573     *
574     * @param { DataBlob } key - the key data blob.
575     * @param { AsyncCallback<SymKey> } callback - the callback of generateSymKey.
576     * @throws { BusinessError } 401 - invalid parameters.
577     * @throws { BusinessError } 17620001 - memory error.
578     * @syscap SystemCapability.Security.CryptoFramework
579     * @since 9
580     */
581    convertKey(key: DataBlob, callback: AsyncCallback<SymKey>): void;
582
583    /**
584     * Generate a symmetric key object according to the provided binary key data.
585     *
586     * @param { DataBlob } key - the key data blob.
587     * @returns { Promise<SymKey> } the promise returned by the function.
588     * @throws { BusinessError } 401 - invalid parameters.
589     * @throws { BusinessError } 17620001 - memory error.
590     * @syscap SystemCapability.Security.CryptoFramework
591     * @since 9
592     */
593    convertKey(key: DataBlob): Promise<SymKey>;
594
595    /**
596     * Indicates the algorithm name of the SymKeyGenerator object.
597     *
598     * @type { string }
599     * @readonly
600     * @syscap SystemCapability.Security.CryptoFramework
601     * @since 9
602     */
603    readonly algName: string;
604  }
605
606  /**
607   * Create the asymmetric key generator instance according to the given algorithm name.
608   *
609   * @param { string } algName - indicates the algorithm name.
610   * @returns { AsyKeyGenerator } the asymmetric key generator instance.
611   * @throws { BusinessError } 401 - invalid parameters.
612   * @throws { BusinessError } 801 - this operation is not supported.
613   * @throws { BusinessError } 17620001 - memory error.
614   * @syscap SystemCapability.Security.CryptoFramework
615   * @since 9
616   */
617  function createAsyKeyGenerator(algName: string): AsyKeyGenerator;
618
619  /**
620   * Create a symmetric key generator according to the given algorithm name.
621   *
622   * @param { string } algName - indicates the algorithm name.
623   * @returns { SymKeyGenerator } the symmetric key generator instance.
624   * @throws { BusinessError } 401 - invalid parameters.
625   * @throws { BusinessError } 801 - this operation is not supported.
626   * @syscap SystemCapability.Security.CryptoFramework
627   * @since 9
628   */
629  function createSymKeyGenerator(algName: string): SymKeyGenerator;
630
631  /**
632   * Provides the Mac type, which is used for Mac generation.
633   *
634   * @typedef Mac
635   * @syscap SystemCapability.Security.CryptoFramework
636   * @since 9
637   */
638  interface Mac {
639    /**
640     * Init hmac with given SymKey.
641     *
642     * @param { SymKey } key - indicates the SymKey.
643     * @param { AsyncCallback<void> } callback - the callback of the init function.
644     * @throws { BusinessError } 401 - invalid parameters.
645     * @throws { BusinessError } 17630001 - crypto operation error.
646     * @syscap SystemCapability.Security.CryptoFramework
647     * @since 9
648     */
649    init(key: SymKey, callback: AsyncCallback<void>): void;
650
651    /**
652     * Init hmac with given SymKey.
653     *
654     * @param { SymKey } key - indicates the SymKey.
655     * @returns { Promise<void> } the promise returned by the function.
656     * @throws { BusinessError } 401 - invalid parameters.
657     * @throws { BusinessError } 17630001 - crypto operation error.
658     * @syscap SystemCapability.Security.CryptoFramework
659     * @since 9
660     */
661    init(key: SymKey): Promise<void>;
662
663    /**
664     * Update hmac with DataBlob.
665     *
666     * @param { DataBlob } input - indicates the DataBlob.
667     * @param { AsyncCallback<void> } callback - the callback of the update function.
668     * @throws { BusinessError } 401 - invalid parameters.
669     * @throws { BusinessError } 17630001 - crypto operation error.
670     * @syscap SystemCapability.Security.CryptoFramework
671     * @since 9
672     */
673    update(input: DataBlob, callback: AsyncCallback<void>): void;
674
675    /**
676     * Update hmac with DataBlob.
677     *
678     * @param { DataBlob } input - indicates the DataBlob.
679     * @returns { Promise<void> } the promise returned by the function.
680     * @throws { BusinessError } 401 - invalid parameters.
681     * @throws { BusinessError } 17630001 - crypto operation error.
682     * @syscap SystemCapability.Security.CryptoFramework
683     * @since 9
684     */
685    update(input: DataBlob): Promise<void>;
686
687    /**
688     * Output the result of hmac calculation.
689     *
690     * @param { AsyncCallback<DataBlob> } callback - the callback of the doFinal function.
691     * @throws { BusinessError } 17620001 - memory error.
692     * @throws { BusinessError } 17630001 - crypto operation error.
693     * @syscap SystemCapability.Security.CryptoFramework
694     * @since 9
695     */
696    doFinal(callback: AsyncCallback<DataBlob>): void;
697
698    /**
699     * Output the result of hmac calculation.
700     *
701     * @returns { Promise<DataBlob> } the promise returned by the function.
702     * @throws { BusinessError } 17620001 - memory error.
703     * @throws { BusinessError } 17630001 - crypto operation error.
704     * @syscap SystemCapability.Security.CryptoFramework
705     * @since 9
706     */
707    doFinal(): Promise<DataBlob>;
708
709    /**
710     * Output the length of hmac result.
711     *
712     * @returns { number } returns the length of the hmac result.
713     * @throws { BusinessError } 17630001 - crypto operation error.
714     * @syscap SystemCapability.Security.CryptoFramework
715     * @since 9
716     */
717    getMacLength(): number;
718
719    /**
720     * Indicates the algorithm name.
721     *
722     * @type { string }
723     * @readonly
724     * @syscap SystemCapability.Security.CryptoFramework
725     * @since 9
726     */
727    readonly algName: string;
728  }
729
730  /**
731   * Provides the mac create func.
732   *
733   * @param { string } algName - indicates the mac algorithm name.
734   * @returns { Mac } returns the created mac instance.
735   * @throws { BusinessError } 401 - invalid parameters.
736   * @throws { BusinessError } 17620001 - memory error.
737   * @syscap SystemCapability.Security.CryptoFramework
738   * @since 9
739   */
740  function createMac(algName: string): Mac;
741
742  /**
743   * Provides the Md type, which is used for Md generation.
744   *
745   * @typedef Md
746   * @syscap SystemCapability.Security.CryptoFramework
747   * @since 9
748   */
749  interface Md {
750    /**
751     * Update md with DataBlob.
752     *
753     * @param { DataBlob } input - indicates the DataBlob.
754     * @param { AsyncCallback<void> } callback - the callback of the update function.
755     * @throws { BusinessError } 401 - invalid parameters.
756     * @throws { BusinessError } 17630001 - crypto operation error.
757     * @syscap SystemCapability.Security.CryptoFramework
758     * @since 9
759     */
760    update(input: DataBlob, callback: AsyncCallback<void>): void;
761
762    /**
763     * Update md with DataBlob.
764     *
765     * @param { DataBlob } input - indicates the DataBlob.
766     * @returns { Promise<void> } the promise returned by the function.
767     * @throws { BusinessError } 401 - invalid parameters.
768     * @throws { BusinessError } 17630001 - crypto operation error.
769     * @syscap SystemCapability.Security.CryptoFramework
770     * @since 9
771     */
772    update(input: DataBlob): Promise<void>;
773
774    /**
775     * Output the result of md calculation.
776     *
777     * @param { AsyncCallback<DataBlob> } callback - the callback of the digest function.
778     * @throws { BusinessError } 17620001 - memory error.
779     * @throws { BusinessError } 17630001 - crypto operation error.
780     * @syscap SystemCapability.Security.CryptoFramework
781     * @since 9
782     */
783    digest(callback: AsyncCallback<DataBlob>): void;
784
785    /**
786     * Output the result of md calculation.
787     *
788     * @returns { Promise<DataBlob> } the promise returned by the function.
789     * @throws { BusinessError } 17620001 - memory error.
790     * @throws { BusinessError } 17630001 - crypto operation error.
791     * @syscap SystemCapability.Security.CryptoFramework
792     * @since 9
793     */
794    digest(): Promise<DataBlob>;
795
796    /**
797     * Output the length of md result.
798     *
799     * @returns { number } returns the length of the hmac result.
800     * @throws { BusinessError } 17630001 - crypto operation error.
801     * @syscap SystemCapability.Security.CryptoFramework
802     * @since 9
803     */
804    getMdLength(): number;
805
806    /**
807     * Indicates the algorithm name.
808     *
809     * @type { string }
810     * @readonly
811     * @syscap SystemCapability.Security.CryptoFramework
812     * @since 9
813     */
814    readonly algName: string;
815  }
816
817  /**
818   * Provides the md create func.
819   *
820   * @param { string } algName - indicates the md algorithm name.
821   * @returns { Md } returns the created md instance.
822   * @throws { BusinessError } 401 - invalid parameters.
823   * @throws { BusinessError } 17620001 - memory error.
824   * @syscap SystemCapability.Security.CryptoFramework
825   * @since 9
826   */
827  function createMd(algName: string): Md;
828
829  /**
830   * Enum for encryption specified parameters.
831   *
832   * @enum { number }
833   * @syscap SystemCapability.Security.CryptoFramework
834   * @since 10
835   */
836  enum CipherSpecItem {
837    /**
838     * Indicates the algorithm name of the message digest function. It is used during RSA encryption.
839     *
840     * @syscap SystemCapability.Security.CryptoFramework
841     * @since 10
842     */
843    OAEP_MD_NAME_STR = 100,
844
845    /**
846     * Indicates the algorithm name for the mask generation function. It is used during RSA encryption.
847     *
848     * @syscap SystemCapability.Security.CryptoFramework
849     * @since 10
850     */
851    OAEP_MGF_NAME_STR = 101,
852
853    /**
854     * Indicates the message digest parameter for the MGF1 mask generation function. It is used during RSA encryption.
855     *
856     * @syscap SystemCapability.Security.CryptoFramework
857     * @since 10
858     */
859    OAEP_MGF1_MD_STR = 102,
860
861    /**
862     * Indicates the source of the encoding input P. It is used during RSA encryption.
863     *
864     * @syscap SystemCapability.Security.CryptoFramework
865     * @since 10
866     */
867    OAEP_MGF1_PSRC_UINT8ARR = 103
868  }
869
870  /**
871   * Enum for signature specified parameters, also used for verification.
872   *
873   * @enum { number }
874   * @syscap SystemCapability.Security.CryptoFramework
875   * @since 10
876   */
877  enum SignSpecItem {
878    /**
879     * Indicates the algorithm name of the message digest function. It is used in RSA signing and verifying process.
880     *
881     * @syscap SystemCapability.Security.CryptoFramework
882     * @since 10
883     */
884    PSS_MD_NAME_STR = 100,
885
886    /**
887     * Indicates the algorithm name of the mask generation function. It is used in RSA signing and verifying process.
888     *
889     * @syscap SystemCapability.Security.CryptoFramework
890     * @since 10
891     */
892    PSS_MGF_NAME_STR = 101,
893
894    /**
895     * Indicates the message digest parameter for the MGF1 mask generation function.
896     * It is used in RSA signing and verifying process.
897     *
898     * @syscap SystemCapability.Security.CryptoFramework
899     * @since 10
900     */
901    PSS_MGF1_MD_STR = 102,
902
903    /**
904     * Indicates the salt length in bits. It is used in RSA signing and verifying process.
905     *
906     * @syscap SystemCapability.Security.CryptoFramework
907     * @since 10
908     */
909    PSS_SALT_LEN_NUM = 103,
910
911    /**
912     * Indicates the value for the trailer field. It is used in RSA signing and verifying process.
913     *
914     * @syscap SystemCapability.Security.CryptoFramework
915     * @since 10
916     */
917    PSS_TRAILER_FIELD_NUM = 104
918  }
919
920  /**
921   * Provides the Cipher type, which is used for encryption and decryption operations.
922   *
923   * @typedef Cipher
924   * @syscap SystemCapability.Security.CryptoFramework
925   * @since 9
926   */
927  interface Cipher {
928    /**
929     * Init the crypto operation with the given crypto mode, key and parameters.
930     *
931     * @param { CryptoMode } opMode - indicates the crypto mode is encryption or decryption.
932     * @param { Key } key - indicates the symmetric key or the asymmetric key.
933     * @param { ParamsSpec } params - indicates the algorithm parameters such as IV.
934     * @param { AsyncCallback<void> } callback - the callback of the init function.
935     * @throws { BusinessError } 401 - invalid parameters.
936     * @throws { BusinessError } 17620001 - memory error.
937     * @throws { BusinessError } 17620002 - runtime error.
938     * @throws { BusinessError } 17630001 - crypto operation error.
939     * @syscap SystemCapability.Security.CryptoFramework
940     * @since 9
941     */
942    init(opMode: CryptoMode, key: Key, params: ParamsSpec, callback: AsyncCallback<void>): void;
943
944    /**
945     * Init the crypto operation with the given crypto mode, key and parameters.
946     *
947     * @param { CryptoMode } opMode - indicates the crypto mode is encryption or decryption.
948     * @param { Key } key - indicates the symmetric key or the asymmetric key.
949     * @param { ParamsSpec | null } params - indicates the algorithm parameters such as IV.
950     * @param { AsyncCallback<void> } callback - the callback of the init function.
951     * @throws { BusinessError } 401 - invalid parameters.
952     * @throws { BusinessError } 17620001 - memory error.
953     * @throws { BusinessError } 17620002 - runtime error.
954     * @throws { BusinessError } 17630001 - crypto operation error.
955     * @syscap SystemCapability.Security.CryptoFramework
956     * @since 10
957     */
958    init(opMode: CryptoMode, key: Key, params: ParamsSpec | null, callback: AsyncCallback<void>): void;
959
960    /**
961     * Init the crypto operation with the given crypto mode, key and parameters.
962     *
963     * @param { CryptoMode } opMode - indicates the crypto mode is encryption or decryption.
964     * @param { Key } key - indicates the symmetric key or the asymmetric key.
965     * @param { ParamsSpec } params - indicates the algorithm parameters such as IV.
966     * @returns { Promise<void> } the promise returned by the function.
967     * @throws { BusinessError } 401 - invalid parameters.
968     * @throws { BusinessError } 17620001 - memory error.
969     * @throws { BusinessError } 17620002 - runtime error.
970     * @throws { BusinessError } 17630001 - crypto operation error.
971     * @syscap SystemCapability.Security.CryptoFramework
972     * @since 9
973     */
974    init(opMode: CryptoMode, key: Key, params: ParamsSpec): Promise<void>;
975
976    /**
977     * Init the crypto operation with the given crypto mode, key and parameters.
978     *
979     * @param { CryptoMode } opMode - indicates the crypto mode is encryption or decryption.
980     * @param { Key } key - indicates the symmetric key or the asymmetric key.
981     * @param { ParamsSpec | null } params - indicates the algorithm parameters such as IV.
982     * @returns { Promise<void> } the promise returned by the function.
983     * @throws { BusinessError } 401 - invalid parameters.
984     * @throws { BusinessError } 17620001 - memory error.
985     * @throws { BusinessError } 17620002 - runtime error.
986     * @throws { BusinessError } 17630001 - crypto operation error.
987     * @syscap SystemCapability.Security.CryptoFramework
988     * @since 10
989     */
990    init(opMode: CryptoMode, key: Key, params: ParamsSpec | null): Promise<void>;
991
992    /**
993     * Update the crypto operation with the input data, and feed back the encrypted or decrypted data
994     * this time. RSA is not supported in this function.
995     *
996     * @param { DataBlob } data - indicates the data to be encrypted or decrypted.
997     * @param { AsyncCallback<DataBlob> } callback - the callback of the update function.
998     * @throws { BusinessError } 401 - invalid parameters.
999     * @throws { BusinessError } 17620001 - memory error.
1000     * @throws { BusinessError } 17620002 - runtime error.
1001     * @throws { BusinessError } 17630001 - crypto operation error.
1002     * @syscap SystemCapability.Security.CryptoFramework
1003     * @since 9
1004     */
1005    update(data: DataBlob, callback: AsyncCallback<DataBlob>): void;
1006
1007    /**
1008     * Update the crypto operation with the input data, and feed back the encrypted or decrypted data
1009     * this time. RSA is not supported in this function.
1010     *
1011     * @param { DataBlob } data - indicates the data to be encrypted or decrypted.
1012     * @returns { Promise<DataBlob> } the promise returned by the function.
1013     * @throws { BusinessError } 401 - invalid parameters.
1014     * @throws { BusinessError } 17620001 - memory error.
1015     * @throws { BusinessError } 17620002 - runtime error.
1016     * @throws { BusinessError } 17630001 - crypto operation error.
1017     * @syscap SystemCapability.Security.CryptoFramework
1018     * @since 9
1019     */
1020    update(data: DataBlob): Promise<DataBlob>;
1021
1022    /**
1023     * Finish the crypto operation, encrypt or decrypt the input data, and then feed back the output data.
1024     * Data cannot be updated after the crypto operation is finished.
1025     *
1026     * @param { DataBlob } data - indicates the data to be finally encrypted or decrypted.
1027     * @param { AsyncCallback<DataBlob> } callback - the callback of the doFinal function.
1028     * @throws { BusinessError } 401 - invalid parameters.
1029     * @throws { BusinessError } 17620001 - memory error.
1030     * @throws { BusinessError } 17620002 - runtime error.
1031     * @throws { BusinessError } 17630001 - crypto operation error.
1032     * @syscap SystemCapability.Security.CryptoFramework
1033     * @since 9
1034     */
1035    doFinal(data: DataBlob, callback: AsyncCallback<DataBlob>): void;
1036
1037    /**
1038     * Finish the crypto operation, encrypt or decrypt the input data, and then feed back the output data.
1039     * Data cannot be updated after the crypto operation is finished.
1040     *
1041     * @param { DataBlob | null } data - indicates the data to be finally encrypted or decrypted.
1042     * @param { AsyncCallback<DataBlob> } callback - the callback of the doFinal function.
1043     * @throws { BusinessError } 401 - invalid parameters.
1044     * @throws { BusinessError } 17620001 - memory error.
1045     * @throws { BusinessError } 17620002 - runtime error.
1046     * @throws { BusinessError } 17630001 - crypto operation error.
1047     * @syscap SystemCapability.Security.CryptoFramework
1048     * @since 10
1049     */
1050    doFinal(data: DataBlob | null, callback: AsyncCallback<DataBlob>): void;
1051
1052    /**
1053     * Finish the crypto operation, encrypt or decrypt the input data, and then feed back the output data.
1054     * Data cannot be updated after the crypto operation is finished.
1055     *
1056     * @param { DataBlob } data - indicates the data to be finally encrypted or decrypted.
1057     * @returns { Promise<DataBlob> } the promise returned by the function.
1058     * @throws { BusinessError } 401 - invalid parameters.
1059     * @throws { BusinessError } 17620001 - memory error.
1060     * @throws { BusinessError } 17620002 - runtime error.
1061     * @throws { BusinessError } 17630001 - crypto operation error.
1062     * @syscap SystemCapability.Security.CryptoFramework
1063     * @since 9
1064     */
1065    doFinal(data: DataBlob): Promise<DataBlob>;
1066
1067    /**
1068     * Finish the crypto operation, encrypt or decrypt the input data, and then feed back the output data.
1069     * Data cannot be updated after the crypto operation is finished.
1070     *
1071     * @param { DataBlob | null } data - indicates the data to be finally encrypted or decrypted.
1072     * @returns { Promise<DataBlob> } the promise returned by the function.
1073     * @throws { BusinessError } 401 - invalid parameters.
1074     * @throws { BusinessError } 17620001 - memory error.
1075     * @throws { BusinessError } 17620002 - runtime error.
1076     * @throws { BusinessError } 17630001 - crypto operation error.
1077     * @syscap SystemCapability.Security.CryptoFramework
1078     * @since 10
1079     */
1080    doFinal(data: DataBlob | null): Promise<DataBlob>;
1081
1082    /**
1083     * Set the specified parameter to the cipher object.
1084     * Currently, only the OAEP_MGF1_PSRC_UINT8ARR parameter in RSA is supported.
1085     *
1086     * @param { CipherSpecItem } itemType - indicates the specified parameter type.
1087     * @param { Uint8Array } itemValue - the value of the specified parameter.
1088     * @throws { BusinessError } 401 - invalid parameters.
1089     * @throws { BusinessError } 801 - this operation is not supported.
1090     * @throws { BusinessError } 17620001 - memory error.
1091     * @throws { BusinessError } 17630001 - crypto operation error.
1092     * @syscap SystemCapability.Security.CryptoFramework
1093     * @since 10
1094     */
1095    setCipherSpec(itemType: CipherSpecItem, itemValue: Uint8Array): void;
1096
1097    /**
1098     * Get the specified parameter from the cipher object.
1099     * Currently, only OAEP parameters in RSA is supported.
1100     *
1101     * @param { CipherSpecItem } itemType - indicates the specified parameter type.
1102     * @returns { string | Uint8Array } the value of the specified parameter.
1103     * @throws { BusinessError } 401 - invalid parameters.
1104     * @throws { BusinessError } 801 - this operation is not supported.
1105     * @throws { BusinessError } 17620001 - memory error.
1106     * @throws { BusinessError } 17630001 - crypto operation error.
1107     * @syscap SystemCapability.Security.CryptoFramework
1108     * @since 10
1109     */
1110    getCipherSpec(itemType: CipherSpecItem): string | Uint8Array;
1111
1112    /**
1113     * Indicates the algorithm name of the cipher object.
1114     *
1115     * @type { string }
1116     * @readonly
1117     * @syscap SystemCapability.Security.CryptoFramework
1118     * @since 9
1119     */
1120    readonly algName: string;
1121  }
1122
1123  /**
1124   * Create a cipher object for encryption and decryption operations according to the given specifications.
1125   * Two different Cipher objects should be created when using RSA encryption and decryption,
1126   * even with the same specifications.
1127   *
1128   * @param { string } transformation - indicates the description to be transformed to cipher specifications.
1129   * @returns { Cipher } the cipher object returned by the function.
1130   * @throws { BusinessError } 401 - invalid parameters.
1131   * @throws { BusinessError } 801 - this operation is not supported.
1132   * @throws { BusinessError } 17620001 - memory error.
1133   * @syscap SystemCapability.Security.CryptoFramework
1134   * @since 9
1135   */
1136  function createCipher(transformation: string): Cipher;
1137
1138  /**
1139   * Provides the Sign type, which is used for generating signatures.
1140   *
1141   * @typedef Sign
1142   * @syscap SystemCapability.Security.CryptoFramework
1143   * @since 9
1144   */
1145  interface Sign {
1146    /**
1147     * Used to init environment.
1148     *
1149     * @param { PriKey } priKey - the private key.
1150     * @param { AsyncCallback<void> } callback - the call back function return nothing.
1151     * @throws { BusinessError } 401 - invalid parameters.
1152     * @throws { BusinessError } 17620001 - memory error.
1153     * @throws { BusinessError } 17620002 - runtime error.
1154     * @throws { BusinessError } 17630001 - crypto operation error.
1155     * @syscap SystemCapability.Security.CryptoFramework
1156     * @since 9
1157     */
1158    init(priKey: PriKey, callback: AsyncCallback<void>): void;
1159
1160    /**
1161     * Used to init environment.
1162     *
1163     * @param { PriKey } priKey - the private key.
1164     * @returns { Promise<void> } return nothing.
1165     * @throws { BusinessError } 401 - invalid parameters.
1166     * @throws { BusinessError } 17620001 - memory error.
1167     * @throws { BusinessError } 17620002 - runtime error.
1168     * @throws { BusinessError } 17630001 - crypto operation error.
1169     * @syscap SystemCapability.Security.CryptoFramework
1170     * @since 9
1171     */
1172    init(priKey: PriKey): Promise<void>;
1173
1174    /**
1175     * Used to append the message need to be signed.
1176     *
1177     * @param { DataBlob } data - the data need to be signed.
1178     * @param { AsyncCallback<void> } callback - the call back function return nothing.
1179     * @throws { BusinessError } 401 - invalid parameters.
1180     * @throws { BusinessError } 17620001 - memory error.
1181     * @throws { BusinessError } 17620002 - runtime error.
1182     * @throws { BusinessError } 17630001 - crypto operation error.
1183     * @syscap SystemCapability.Security.CryptoFramework
1184     * @since 9
1185     */
1186    update(data: DataBlob, callback: AsyncCallback<void>): void;
1187
1188    /**
1189     * Used to append the message need to be signed.
1190     *
1191     * @param { DataBlob } data - the data need to be signed.
1192     * @returns { Promise<void> } return nothing.
1193     * @throws { BusinessError } 401 - invalid parameters.
1194     * @throws { BusinessError } 17620001 - memory error.
1195     * @throws { BusinessError } 17620002 - runtime error.
1196     * @throws { BusinessError } 17630001 - crypto operation error.
1197     * @syscap SystemCapability.Security.CryptoFramework
1198     * @since 9
1199     */
1200    update(data: DataBlob): Promise<void>;
1201
1202    /**
1203     * Used to sign message, include the update data.
1204     *
1205     * @param { DataBlob } data - the data need to be signed.
1206     * @param { AsyncCallback<DataBlob> } callback - return the signed message.
1207     * @throws { BusinessError } 401 - invalid parameters.
1208     * @throws { BusinessError } 17620001 - memory error.
1209     * @throws { BusinessError } 17620002 - runtime error.
1210     * @throws { BusinessError } 17630001 - crypto operation error.
1211     * @syscap SystemCapability.Security.CryptoFramework
1212     * @since 9
1213     */
1214    sign(data: DataBlob, callback: AsyncCallback<DataBlob>): void;
1215
1216    /**
1217     * Used to sign message, include the update data.
1218     *
1219     * @param { DataBlob | null } data - the data need to be signed.
1220     * @param { AsyncCallback<DataBlob> } callback - return the signed message.
1221     * @throws { BusinessError } 401 - invalid parameters.
1222     * @throws { BusinessError } 17620001 - memory error.
1223     * @throws { BusinessError } 17620002 - runtime error.
1224     * @throws { BusinessError } 17630001 - crypto operation error.
1225     * @syscap SystemCapability.Security.CryptoFramework
1226     * @since 10
1227     */
1228    sign(data: DataBlob | null, callback: AsyncCallback<DataBlob>): void;
1229
1230    /**
1231     * Used to append the message need to be signed.
1232     *
1233     * @param { DataBlob } data - the private key.
1234     * @returns { Promise<DataBlob> } return the signed message.
1235     * @throws { BusinessError } 401 - invalid parameters.
1236     * @throws { BusinessError } 17620001 - memory error.
1237     * @throws { BusinessError } 17620002 - runtime error.
1238     * @throws { BusinessError } 17630001 - crypto operation error.
1239     * @syscap SystemCapability.Security.CryptoFramework
1240     * @since 9
1241     */
1242    sign(data: DataBlob): Promise<DataBlob>;
1243
1244    /**
1245     * Used to append the message need to be signed.
1246     *
1247     * @param { DataBlob | null } data - the private key.
1248     * @returns { Promise<DataBlob> } return the signed message.
1249     * @throws { BusinessError } 401 - invalid parameters.
1250     * @throws { BusinessError } 17620001 - memory error.
1251     * @throws { BusinessError } 17620002 - runtime error.
1252     * @throws { BusinessError } 17630001 - crypto operation error.
1253     * @syscap SystemCapability.Security.CryptoFramework
1254     * @since 10
1255     */
1256    sign(data: DataBlob | null): Promise<DataBlob>;
1257
1258    /**
1259     * Set the specified parameter to the sign object.
1260     * Currently, only the PSS_SALT_LEN parameter in RSA is supported.
1261     *
1262     * @param { SignSpecItem } itemType - indicates the specified parameter type.
1263     * @param { number } itemValue - the value of the specified parameter.
1264     * @throws { BusinessError } 401 - invalid parameters.
1265     * @throws { BusinessError } 801 - this operation is not supported.
1266     * @throws { BusinessError } 17620001 - memory error.
1267     * @throws { BusinessError } 17630001 - crypto operation error.
1268     * @syscap SystemCapability.Security.CryptoFramework
1269     * @since 10
1270     */
1271    setSignSpec(itemType: SignSpecItem, itemValue: number): void;
1272
1273    /**
1274     * Get the specified parameter from the sign object.
1275     * Currently, only PSS parameters in RSA is supported.
1276     *
1277     * @param { SignSpecItem } itemType - indicates the specified parameter type.
1278     * @returns { string | number } the value of the specified parameter.
1279     * @throws { BusinessError } 401 - invalid parameters.
1280     * @throws { BusinessError } 801 - this operation is not supported.
1281     * @throws { BusinessError } 17620001 - memory error.
1282     * @throws { BusinessError } 17630001 - crypto operation error.
1283     * @syscap SystemCapability.Security.CryptoFramework
1284     * @since 10
1285     */
1286    getSignSpec(itemType: SignSpecItem): string | number;
1287
1288    /**
1289     * Indicates the algorithm name of the sign object.
1290     *
1291     * @type { string }
1292     * @readonly
1293     * @syscap SystemCapability.Security.CryptoFramework
1294     * @since 9
1295     */
1296    readonly algName: string;
1297  }
1298
1299  /**
1300   * Provides the Verify interface, which is used for verifying signatures.
1301   *
1302   * @typedef Verify
1303   * @syscap SystemCapability.Security.CryptoFramework
1304   * @since 9
1305   */
1306  interface Verify {
1307    /**
1308     * Used to init environment.
1309     *
1310     * @param { PubKey } pubKey - the public key.
1311     * @param { AsyncCallback<void> } callback - return nothing.
1312     * @throws { BusinessError } 401 - invalid parameters.
1313     * @throws { BusinessError } 17620001 - memory error.
1314     * @throws { BusinessError } 17620002 - runtime error.
1315     * @throws { BusinessError } 17630001 - crypto operation error.
1316     * @syscap SystemCapability.Security.CryptoFramework
1317     * @since 9
1318     */
1319    init(pubKey: PubKey, callback: AsyncCallback<void>): void;
1320
1321    /**
1322     * Used to init environment.
1323     *
1324     * @param { PubKey } pubKey - the public key.
1325     * @returns { Promise<void> } return nothing.
1326     * @throws { BusinessError } 401 - invalid parameters.
1327     * @throws { BusinessError } 17620001 - memory error.
1328     * @throws { BusinessError } 17620002 - runtime error.
1329     * @throws { BusinessError } 17630001 - crypto operation error.
1330     * @syscap SystemCapability.Security.CryptoFramework
1331     * @since 9
1332     */
1333    init(pubKey: PubKey): Promise<void>;
1334
1335    /**
1336     * Used to append the message need to be verified.
1337     *
1338     * @param { DataBlob } data - the data need to be verified.
1339     * @param { AsyncCallback<void> } callback - return nothing.
1340     * @throws { BusinessError } 401 - invalid parameters.
1341     * @throws { BusinessError } 17620001 - memory error.
1342     * @throws { BusinessError } 17620002 - runtime error.
1343     * @throws { BusinessError } 17630001 - crypto operation error.
1344     * @syscap SystemCapability.Security.CryptoFramework
1345     * @since 9
1346     */
1347    update(data: DataBlob, callback: AsyncCallback<void>): void;
1348
1349    /**
1350     * Used to append the message need to be verified.
1351     *
1352     * @param { DataBlob } data - the data need to be verified.
1353     * @returns { Promise<void> } return nothing.
1354     * @throws { BusinessError } 401 - invalid parameters.
1355     * @throws { BusinessError } 17620001 - memory error.
1356     * @throws { BusinessError } 17620002 - runtime error.
1357     * @throws { BusinessError } 17630001 - crypto operation error.
1358     * @syscap SystemCapability.Security.CryptoFramework
1359     * @since 9
1360     */
1361    update(data: DataBlob): Promise<void>;
1362
1363    /**
1364     * Used to verify message, include the update data.
1365     *
1366     * @param { DataBlob } data - the data need to be verified.
1367     * @param { DataBlob } signatureData - the signature data.
1368     * @param { AsyncCallback<boolean> } callback - return the verify result.
1369     * @throws { BusinessError } 401 - invalid parameters.
1370     * @throws { BusinessError } 17620001 - memory error.
1371     * @throws { BusinessError } 17620002 - runtime error.
1372     * @throws { BusinessError } 17630001 - crypto operation error.
1373     * @syscap SystemCapability.Security.CryptoFramework
1374     * @since 9
1375     */
1376    verify(data: DataBlob, signatureData: DataBlob, callback: AsyncCallback<boolean>): void;
1377
1378    /**
1379     * Used to verify message, include the update data.
1380     *
1381     * @param { DataBlob | null } data - the data need to be verified.
1382     * @param { DataBlob } signatureData - the signature data.
1383     * @param { AsyncCallback<boolean> } callback - return the verify result.
1384     * @throws { BusinessError } 401 - invalid parameters.
1385     * @throws { BusinessError } 17620001 - memory error.
1386     * @throws { BusinessError } 17620002 - runtime error.
1387     * @throws { BusinessError } 17630001 - crypto operation error.
1388     * @syscap SystemCapability.Security.CryptoFramework
1389     * @since 10
1390     */
1391    verify(data: DataBlob | null, signatureData: DataBlob, callback: AsyncCallback<boolean>): void;
1392
1393    /**
1394     * Used to verify message, include the update data.
1395     *
1396     * @param { DataBlob } data - the data need to be verified.
1397     * @param { DataBlob } signatureData - the signature data.
1398     * @returns { Promise<boolean> } return the verify result.
1399     * @throws { BusinessError } 401 - invalid parameters.
1400     * @throws { BusinessError } 17620001 - memory error.
1401     * @throws { BusinessError } 17620002 - runtime error.
1402     * @throws { BusinessError } 17630001 - crypto operation error.
1403     * @syscap SystemCapability.Security.CryptoFramework
1404     * @since 9
1405     */
1406    verify(data: DataBlob, signatureData: DataBlob): Promise<boolean>;
1407
1408    /**
1409     * Used to verify message, include the update data.
1410     *
1411     * @param { DataBlob | null } data - the data need to be verified.
1412     * @param { DataBlob } signatureData - the signature data.
1413     * @returns { Promise<boolean> } return the verify result.
1414     * @throws { BusinessError } 401 - invalid parameters.
1415     * @throws { BusinessError } 17620001 - memory error.
1416     * @throws { BusinessError } 17620002 - runtime error.
1417     * @throws { BusinessError } 17630001 - crypto operation error.
1418     * @syscap SystemCapability.Security.CryptoFramework
1419     * @since 10
1420     */
1421    verify(data: DataBlob | null, signatureData: DataBlob): Promise<boolean>;
1422
1423    /**
1424     * Set the specified parameter to the verify object.
1425     * Currently, only the PSS_SALT_LEN parameter in RSA is supported.
1426     *
1427     * @param { SignSpecItem } itemType - indicates the specified parameter type.
1428     * @param { number } itemValue - the value of the specified parameter.
1429     * @throws { BusinessError } 401 - invalid parameters.
1430     * @throws { BusinessError } 801 - this operation is not supported.
1431     * @throws { BusinessError } 17620001 - memory error.
1432     * @throws { BusinessError } 17630001 - crypto operation error.
1433     * @syscap SystemCapability.Security.CryptoFramework
1434     * @since 10
1435     */
1436    setVerifySpec(itemType: SignSpecItem, itemValue: number): void;
1437
1438    /**
1439     * Get the specified parameter from the verify object.
1440     * Currently, only PSS parameters in RSA is supported.
1441     *
1442     * @param { SignSpecItem } itemType - indicates the specified parameter type.
1443     * @returns { string | number } the value of the specified parameter.
1444     * @throws { BusinessError } 401 - invalid parameters.
1445     * @throws { BusinessError } 801 - this operation is not supported.
1446     * @throws { BusinessError } 17620001 - memory error.
1447     * @throws { BusinessError } 17630001 - crypto operation error.
1448     * @syscap SystemCapability.Security.CryptoFramework
1449     * @since 10
1450     */
1451    getVerifySpec(itemType: SignSpecItem): string | number;
1452
1453    /**
1454     * Indicates the algorithm name of the verify object.
1455     *
1456     * @type { string }
1457     * @readonly
1458     * @syscap SystemCapability.Security.CryptoFramework
1459     * @since 9
1460     */
1461    readonly algName: string;
1462  }
1463
1464  /**
1465   * Create a sign object for generating signatures.
1466   *
1467   * @param { string } algName - indicates the algorithm name and params.
1468   * @returns { Sign } the sign class.
1469   * @throws { BusinessError } 401 - invalid parameters.
1470   * @throws { BusinessError } 801 - this operation is not supported.
1471   * @throws { BusinessError } 17620001 - memory error.
1472   * @syscap SystemCapability.Security.CryptoFramework
1473   * @since 9
1474   */
1475  function createSign(algName: string): Sign;
1476
1477  /**
1478   * Create a verify object for verifying signatures.
1479   *
1480   * @param { string } algName - indicates the algorithm name and the parameters.
1481   * @returns { Verify } the verify class.
1482   * @throws { BusinessError } 401 - invalid parameters.
1483   * @throws { BusinessError } 801 - this operation is not supported.
1484   * @throws { BusinessError } 17620001 - memory error.
1485   * @syscap SystemCapability.Security.CryptoFramework
1486   * @since 9
1487   */
1488  function createVerify(algName: string): Verify;
1489
1490  /**
1491   * Provides key agreement function.
1492   *
1493   * @typedef KeyAgreement
1494   * @syscap SystemCapability.Security.CryptoFramework
1495   * @since 9
1496   */
1497  interface KeyAgreement {
1498    /**
1499     * Used to generate secret.
1500     *
1501     * @param { PriKey } priKey - the private key.
1502     * @param { PubKey } pubKey - the public key.
1503     * @param { AsyncCallback<DataBlob> } callback - return the secret.
1504     * @throws { BusinessError } 401 - invalid parameters.
1505     * @throws { BusinessError } 17620001 - memory error.
1506     * @throws { BusinessError } 17620002 - runtime error.
1507     * @throws { BusinessError } 17630001 - crypto operation error.
1508     * @syscap SystemCapability.Security.CryptoFramework
1509     * @since 9
1510     */
1511    generateSecret(priKey: PriKey, pubKey: PubKey, callback: AsyncCallback<DataBlob>): void;
1512
1513    /**
1514     * Used to generate secret.
1515     *
1516     * @param { PriKey } priKey - the private key.
1517     * @param { PubKey } pubKey - the public key.
1518     * @returns { Promise<DataBlob> } the promise used to return secret.
1519     * @throws { BusinessError } 401 - invalid parameters.
1520     * @throws { BusinessError } 17620001 - memory error.
1521     * @throws { BusinessError } 17620002 - runtime error.
1522     * @throws { BusinessError } 17630001 - crypto operation error.
1523     * @syscap SystemCapability.Security.CryptoFramework
1524     * @since 9
1525     */
1526    generateSecret(priKey: PriKey, pubKey: PubKey): Promise<DataBlob>;
1527
1528    /**
1529     * Indicates the algorithm name.
1530     *
1531     * @type { string }
1532     * @readonly
1533     * @syscap SystemCapability.Security.CryptoFramework
1534     * @since 9
1535     */
1536    readonly algName: string;
1537  }
1538
1539  /**
1540   * Create a key agreement object.
1541   *
1542   * @param { string } algName - indicates the algorithm name and params.
1543   * @returns { KeyAgreement } the key agreement object.
1544   * @throws { BusinessError } 401 - invalid parameters.
1545   * @throws { BusinessError } 801 - this operation is not supported.
1546   * @throws { BusinessError } 17620001 - memory error.
1547   * @syscap SystemCapability.Security.CryptoFramework
1548   * @since 9
1549   */
1550  function createKeyAgreement(algName: string): KeyAgreement;
1551
1552  /**
1553   * Enum for algorithm specified parameters.
1554   *
1555   * @enum { number }
1556   * @syscap SystemCapability.Security.CryptoFramework
1557   * @since 10
1558   */
1559  enum AsyKeySpecItem {
1560    /**
1561     * Indicates the DSA prime p.
1562     *
1563     * @syscap SystemCapability.Security.CryptoFramework
1564     * @since 10
1565     */
1566    DSA_P_BN = 101,
1567
1568    /**
1569     * Indicates the DSA sub-prime q.
1570     *
1571     * @syscap SystemCapability.Security.CryptoFramework
1572     * @since 10
1573     */
1574    DSA_Q_BN = 102,
1575
1576    /**
1577     * Indicates the DSA base g.
1578     *
1579     * @syscap SystemCapability.Security.CryptoFramework
1580     * @since 10
1581     */
1582    DSA_G_BN = 103,
1583
1584    /**
1585     * Indicates the DSA private key.
1586     *
1587     * @syscap SystemCapability.Security.CryptoFramework
1588     * @since 10
1589     */
1590    DSA_SK_BN = 104,
1591
1592    /**
1593     * Indicates the DSA public key.
1594     *
1595     * @syscap SystemCapability.Security.CryptoFramework
1596     * @since 10
1597     */
1598    DSA_PK_BN = 105,
1599
1600    /**
1601     * Indicates the prime p of an elliptic curve (EC) prime finite field.
1602     *
1603     * @syscap SystemCapability.Security.CryptoFramework
1604     * @since 10
1605     */
1606    ECC_FP_P_BN = 201,
1607
1608    /**
1609     * Indicates the first coefficient a of this elliptic curve.
1610     *
1611     * @syscap SystemCapability.Security.CryptoFramework
1612     * @since 10
1613     */
1614    ECC_A_BN = 202,
1615
1616    /**
1617     * Indicates the second coefficient b of this elliptic curve.
1618     *
1619     * @syscap SystemCapability.Security.CryptoFramework
1620     * @since 10
1621     */
1622    ECC_B_BN = 203,
1623
1624    /**
1625     * Indicates the affine x-coordinate of base point g.
1626     *
1627     * @syscap SystemCapability.Security.CryptoFramework
1628     * @since 10
1629     */
1630    ECC_G_X_BN = 204,
1631
1632    /**
1633     * Indicates the affine y-coordinate of base point g.
1634     *
1635     * @syscap SystemCapability.Security.CryptoFramework
1636     * @since 10
1637     */
1638    ECC_G_Y_BN = 205,
1639
1640    /**
1641     * Indicates the order of the base point g.
1642     *
1643     * @syscap SystemCapability.Security.CryptoFramework
1644     * @since 10
1645     */
1646    ECC_N_BN = 206,
1647
1648    /**
1649     * Indicates the cofactor of the elliptic curve.
1650     *
1651     * @syscap SystemCapability.Security.CryptoFramework
1652     * @since 10
1653     */
1654    ECC_H_NUM = 207,
1655
1656    /**
1657     * Indicates the private value of the ECC private key.
1658     *
1659     * @syscap SystemCapability.Security.CryptoFramework
1660     * @since 10
1661     */
1662    ECC_SK_BN = 208,
1663
1664    /**
1665     * Indicates the affine x-coordinate of a point, which is the public point of an ECC public key.
1666     *
1667     * @syscap SystemCapability.Security.CryptoFramework
1668     * @since 10
1669     */
1670    ECC_PK_X_BN = 209,
1671
1672    /**
1673     * Indicates the affine y-coordinate of a point, which is the public point of an ECC public key.
1674     *
1675     * @syscap SystemCapability.Security.CryptoFramework
1676     * @since 10
1677     */
1678    ECC_PK_Y_BN = 210,
1679
1680    /**
1681     * Indicates an elliptic curve finite field type.
1682     *
1683     * @syscap SystemCapability.Security.CryptoFramework
1684     * @since 10
1685     */
1686    ECC_FIELD_TYPE_STR = 211,
1687
1688    /**
1689     * Indicates the field size in bits.
1690     * For Fp field (an elliptic curve prime finite field with prime p), the field size is the size of prime p.
1691     *
1692     * @syscap SystemCapability.Security.CryptoFramework
1693     * @since 10
1694     */
1695    ECC_FIELD_SIZE_NUM = 212,
1696
1697    /**
1698     * Indicates the curve name according to SECG (Standards for Efficient Cryptography Group).
1699     *
1700     * @syscap SystemCapability.Security.CryptoFramework
1701     * @since 10
1702     */
1703    ECC_CURVE_NAME_STR = 213,
1704
1705    /**
1706     * Indicates the modulus n of RSA algorithm.
1707     *
1708     * @syscap SystemCapability.Security.CryptoFramework
1709     * @since 10
1710     */
1711    RSA_N_BN = 301,
1712
1713    /**
1714     * Indicates the private exponent d of RSA algorithm.
1715     *
1716     * @syscap SystemCapability.Security.CryptoFramework
1717     * @since 10
1718     */
1719    RSA_SK_BN = 302,
1720
1721    /**
1722     * Indicates the public exponent e of RSA algorithm.
1723     *
1724     * @syscap SystemCapability.Security.CryptoFramework
1725     * @since 10
1726     */
1727    RSA_PK_BN = 303
1728  }
1729
1730  /**
1731   * Enum for algorithm specified parameters type.
1732   *
1733   * @enum { number }
1734   * @syscap SystemCapability.Security.CryptoFramework
1735   * @since 10
1736   */
1737  enum AsyKeySpecType {
1738    /**
1739     * Indicates the common specified parameters.
1740     *
1741     * @syscap SystemCapability.Security.CryptoFramework
1742     * @since 10
1743     */
1744    COMMON_PARAMS_SPEC = 0,
1745
1746    /**
1747     * Indicates the specified parameters of private key.
1748     *
1749     * @syscap SystemCapability.Security.CryptoFramework
1750     * @since 10
1751     */
1752    PRIVATE_KEY_SPEC = 1,
1753
1754    /**
1755     * Indicates the specified parameters of public key.
1756     *
1757     * @syscap SystemCapability.Security.CryptoFramework
1758     * @since 10
1759     */
1760    PUBLIC_KEY_SPEC = 2,
1761
1762    /**
1763     * Indicates the specified parameters of keypair.
1764     *
1765     * @syscap SystemCapability.Security.CryptoFramework
1766     * @since 10
1767     */
1768    KEY_PAIR_SPEC = 3
1769  }
1770
1771  /**
1772   * Provides a base interface for specifying asymmetric key parameters.
1773   *
1774   * @typedef AsyKeySpec
1775   * @syscap SystemCapability.Security.CryptoFramework
1776   * @since 10
1777   */
1778  interface AsyKeySpec {
1779    /**
1780     * Indicates the algorithm name of the asymmetric key object.
1781     *
1782     * @type { string }
1783     * @syscap SystemCapability.Security.CryptoFramework
1784     * @since 10
1785     */
1786    algName: string;
1787
1788    /**
1789     * Indicates the type of the specified parameters.
1790     *
1791     * @type { AsyKeySpecType }
1792     * @syscap SystemCapability.Security.CryptoFramework
1793     * @since 10
1794     */
1795    specType: AsyKeySpecType;
1796  }
1797
1798  /**
1799   * Specifies the set of parameters used in the DSA algorithm.
1800   *
1801   * @typedef DSACommonParamsSpec
1802   * @syscap SystemCapability.Security.CryptoFramework
1803   * @since 10
1804   */
1805  interface DSACommonParamsSpec extends AsyKeySpec {
1806    /**
1807     * Indicates the DSA prime p.
1808     *
1809     * @type { bigint }
1810     * @syscap SystemCapability.Security.CryptoFramework
1811     * @since 10
1812     */
1813    p: bigint;
1814
1815    /**
1816     * Indicates the DSA sub-prime q.
1817     *
1818     * @type { bigint }
1819     * @syscap SystemCapability.Security.CryptoFramework
1820     * @since 10
1821     */
1822    q: bigint;
1823
1824    /**
1825     * Indicates the DSA base g.
1826     *
1827     * @type { bigint }
1828     * @syscap SystemCapability.Security.CryptoFramework
1829     * @since 10
1830     */
1831    g: bigint;
1832  }
1833
1834  /**
1835   * Specifies the DSA public key with its associated parameters.
1836   *
1837   * @typedef DSAPubKeySpec
1838   * @syscap SystemCapability.Security.CryptoFramework
1839   * @since 10
1840   */
1841  interface DSAPubKeySpec extends AsyKeySpec {
1842    /**
1843     * Indicates the DSA common parameters.
1844     *
1845     * @type { DSACommonParamsSpec }
1846     * @syscap SystemCapability.Security.CryptoFramework
1847     * @since 10
1848     */
1849    params: DSACommonParamsSpec;
1850
1851    /**
1852     * Indicates the DSA public key.
1853     *
1854     * @type { bigint }
1855     * @syscap SystemCapability.Security.CryptoFramework
1856     * @since 10
1857     */
1858    pk: bigint;
1859  }
1860
1861  /**
1862   * Specifies the DSA keypair with its associated parameters.
1863   *
1864   * @typedef DSAKeyPairSpec
1865   * @syscap SystemCapability.Security.CryptoFramework
1866   * @since 10
1867   */
1868  interface DSAKeyPairSpec extends AsyKeySpec {
1869    /**
1870     * Indicates the DSA common parameters.
1871     *
1872     * @type { DSACommonParamsSpec }
1873     * @syscap SystemCapability.Security.CryptoFramework
1874     * @since 10
1875     */
1876    params: DSACommonParamsSpec;
1877
1878    /**
1879     * Indicates the DSA private key.
1880     *
1881     * @type { bigint }
1882     * @syscap SystemCapability.Security.CryptoFramework
1883     * @since 10
1884     */
1885    sk: bigint;
1886
1887    /**
1888     * Indicates the DSA public key.
1889     *
1890     * @type { bigint }
1891     * @syscap SystemCapability.Security.CryptoFramework
1892     * @since 10
1893     */
1894    pk: bigint;
1895  }
1896
1897  /**
1898   * Specifies an elliptic curve finite field.
1899   *
1900   * @typedef ECField
1901   * @syscap SystemCapability.Security.CryptoFramework
1902   * @since 10
1903   */
1904  interface ECField {
1905    /**
1906     * Indicates the type of an elliptic curve finite field.
1907     * Currently, only Fp (elliptic curve prime finite field) is supported.
1908     *
1909     * @type { string }
1910     * @syscap SystemCapability.Security.CryptoFramework
1911     * @since 10
1912     */
1913    fieldType: string;
1914  }
1915
1916  /**
1917   * Specifies an elliptic curve finite field with the prime p.
1918   *
1919   * @typedef ECFieldFp
1920   * @syscap SystemCapability.Security.CryptoFramework
1921   * @since 10
1922   */
1923  interface ECFieldFp extends ECField {
1924    /**
1925     * Indicates the prime p.
1926     *
1927     * @type { bigint }
1928     * @syscap SystemCapability.Security.CryptoFramework
1929     * @since 10
1930     */
1931    p: bigint;
1932  }
1933
1934  /**
1935   * Represents a point on an elliptic curve in affine coordinates.
1936   *
1937   * @typedef Point
1938   * @syscap SystemCapability.Security.CryptoFramework
1939   * @since 10
1940   */
1941  interface Point {
1942    /**
1943     * Indicates the affine x-coordinate.
1944     *
1945     * @type { bigint }
1946     * @syscap SystemCapability.Security.CryptoFramework
1947     * @since 10
1948     */
1949    x: bigint;
1950
1951    /**
1952     * Indicates the affine y-coordinate.
1953     *
1954     * @type { bigint }
1955     * @syscap SystemCapability.Security.CryptoFramework
1956     * @since 10
1957     */
1958    y: bigint;
1959  }
1960
1961  /**
1962   * Specifies the set of common parameters used in the ECC algorithm.
1963   *
1964   * @typedef ECCCommonParamsSpec
1965   * @syscap SystemCapability.Security.CryptoFramework
1966   * @since 10
1967   */
1968  interface ECCCommonParamsSpec extends AsyKeySpec {
1969    /**
1970     * Indicates an elliptic curve finite field.
1971     *
1972     * @type { ECField }
1973     * @syscap SystemCapability.Security.CryptoFramework
1974     * @since 10
1975     */
1976    field: ECField;
1977
1978    /**
1979     * Indicates the first coefficient a of the elliptic curve.
1980     *
1981     * @type { bigint }
1982     * @syscap SystemCapability.Security.CryptoFramework
1983     * @since 10
1984     */
1985    a: bigint;
1986
1987    /**
1988     * Indicates the second coefficient b of the elliptic curve.
1989     *
1990     * @type { bigint }
1991     * @syscap SystemCapability.Security.CryptoFramework
1992     * @since 10
1993     */
1994    b: bigint;
1995
1996    /**
1997     * Indicates the base point g.
1998     *
1999     * @type { Point }
2000     * @syscap SystemCapability.Security.CryptoFramework
2001     * @since 10
2002     */
2003    g: Point;
2004
2005    /**
2006     * Indicates the order of the base point g.
2007     *
2008     * @type { bigint }
2009     * @syscap SystemCapability.Security.CryptoFramework
2010     * @since 10
2011     */
2012    n: bigint;
2013
2014    /**
2015     * Indicates the cofactor h.
2016     *
2017     * @type { number }
2018     * @syscap SystemCapability.Security.CryptoFramework
2019     * @since 10
2020     */
2021    h: number;
2022  }
2023
2024  /**
2025   * Specifies the ECC private key with its associated parameters.
2026   *
2027   * @typedef ECCPriKeySpec
2028   * @syscap SystemCapability.Security.CryptoFramework
2029   * @since 10
2030   */
2031  interface ECCPriKeySpec extends AsyKeySpec {
2032    /**
2033     * Indicates the ECC common parameters.
2034     *
2035     * @type { ECCCommonParamsSpec }
2036     * @syscap SystemCapability.Security.CryptoFramework
2037     * @since 10
2038     */
2039    params: ECCCommonParamsSpec;
2040
2041    /**
2042     * Indicates the private value of the ECC private key.
2043     *
2044     * @type { bigint }
2045     * @syscap SystemCapability.Security.CryptoFramework
2046     * @since 10
2047     */
2048    sk: bigint;
2049  }
2050
2051  /**
2052   * Specifies the ECC public key with its associated parameters.
2053   *
2054   * @typedef ECCPubKeySpec
2055   * @syscap SystemCapability.Security.CryptoFramework
2056   * @since 10
2057   */
2058  interface ECCPubKeySpec extends AsyKeySpec {
2059    /**
2060     * Indicates the ECC common parameters.
2061     *
2062     * @type { ECCCommonParamsSpec }
2063     * @syscap SystemCapability.Security.CryptoFramework
2064     * @since 10
2065     */
2066    params: ECCCommonParamsSpec;
2067
2068    /**
2069     * Indicates the public point of the ECC public key.
2070     *
2071     * @type { Point }
2072     * @syscap SystemCapability.Security.CryptoFramework
2073     * @since 10
2074     */
2075    pk: Point;
2076  }
2077
2078  /**
2079   * Specifies the ECC keypair with its associated parameters.
2080   *
2081   * @typedef ECCKeyPairSpec
2082   * @syscap SystemCapability.Security.CryptoFramework
2083   * @since 10
2084   */
2085  interface ECCKeyPairSpec extends AsyKeySpec {
2086    /**
2087     * Indicates the ECC common parameters.
2088     *
2089     * @type { ECCCommonParamsSpec }
2090     * @syscap SystemCapability.Security.CryptoFramework
2091     * @since 10
2092     */
2093    params: ECCCommonParamsSpec;
2094
2095    /**
2096     * Indicates the private value of the ECC private key.
2097     *
2098     * @type { bigint }
2099     * @syscap SystemCapability.Security.CryptoFramework
2100     * @since 10
2101     */
2102    sk: bigint;
2103
2104    /**
2105     * Indicates the public point of the ECC public key.
2106     *
2107     * @type { Point }
2108     * @syscap SystemCapability.Security.CryptoFramework
2109     * @since 10
2110     */
2111    pk: Point;
2112  }
2113
2114  /**
2115   * Specifies the set of common parameters used in the RSA algorithm.
2116   *
2117   * @typedef RSACommonParamsSpec
2118   * @syscap SystemCapability.Security.CryptoFramework
2119   * @since 10
2120   */
2121  interface RSACommonParamsSpec extends AsyKeySpec {
2122    /**
2123     * Indicates the modulus n.
2124     *
2125     * @type { bigint }
2126     * @syscap SystemCapability.Security.CryptoFramework
2127     * @since 10
2128     */
2129    n: bigint;
2130  }
2131
2132  /**
2133   * Specifies the RSA public key with its associated parameters.
2134   *
2135   * @typedef RSAPubKeySpec
2136   * @syscap SystemCapability.Security.CryptoFramework
2137   * @since 10
2138   */
2139  interface RSAPubKeySpec extends AsyKeySpec {
2140    /**
2141     * Indicates the RSA common parameters.
2142     *
2143     * @type { RSACommonParamsSpec }
2144     * @syscap SystemCapability.Security.CryptoFramework
2145     * @since 10
2146     */
2147    params: RSACommonParamsSpec;
2148
2149    /**
2150     * Indicates the public exponent e.
2151     *
2152     * @type { bigint }
2153     * @syscap SystemCapability.Security.CryptoFramework
2154     * @since 10
2155     */
2156    pk: bigint;
2157  }
2158
2159  /**
2160   * Specifies the RSA keypair with its associated parameters.
2161   *
2162   * @typedef RSAKeyPairSpec
2163   * @syscap SystemCapability.Security.CryptoFramework
2164   * @since 10
2165   */
2166  interface RSAKeyPairSpec extends AsyKeySpec {
2167    /**
2168     * Indicates the RSA common parameters.
2169     *
2170     * @type { RSACommonParamsSpec }
2171     * @syscap SystemCapability.Security.CryptoFramework
2172     * @since 10
2173     */
2174    params: RSACommonParamsSpec;
2175
2176    /**
2177     * Indicates the private exponent d.
2178     *
2179     * @type { bigint }
2180     * @syscap SystemCapability.Security.CryptoFramework
2181     * @since 10
2182     */
2183    sk: bigint;
2184
2185    /**
2186     * Indicates the public exponent e.
2187     *
2188     * @type { bigint }
2189     * @syscap SystemCapability.Security.CryptoFramework
2190     * @since 10
2191     */
2192    pk: bigint;
2193  }
2194
2195  /**
2196   * The AsyKeyGeneratorBySpec provides the ability to generate key with its associated parameters.
2197   *
2198   * @typedef AsyKeyGeneratorBySpec
2199   * @syscap SystemCapability.Security.CryptoFramework
2200   * @since 10
2201   */
2202  interface AsyKeyGeneratorBySpec {
2203    /**
2204     * Generate an asymmetric keypair.
2205     *
2206     * @param { AsyncCallback<KeyPair> } callback - the callback used to return keypair.
2207     * @throws { BusinessError } 401 - invalid parameters.
2208     * @throws { BusinessError } 17620001 - memory error.
2209     * @throws { BusinessError } 17630001 - crypto operation error.
2210     * @syscap SystemCapability.Security.CryptoFramework
2211     * @since 10
2212     */
2213    generateKeyPair(callback: AsyncCallback<KeyPair>): void;
2214
2215    /**
2216     * Generate an asymmetric keypair.
2217     *
2218     * @returns { Promise<KeyPair> } the promise used to return keypair.
2219     * @throws { BusinessError } 401 - invalid parameters.
2220     * @throws { BusinessError } 17620001 - memory error.
2221     * @throws { BusinessError } 17630001 - crypto operation error.
2222     * @syscap SystemCapability.Security.CryptoFramework
2223     * @since 10
2224     */
2225    generateKeyPair(): Promise<KeyPair>;
2226
2227    /**
2228     * Generate a private key instance.
2229     *
2230     * @param { AsyncCallback<PriKey> } callback - the callback used to return PriKey.
2231     * @throws { BusinessError } 401 - invalid parameters.
2232     * @throws { BusinessError } 17620001 - memory error.
2233     * @throws { BusinessError } 17630001 - crypto operation error.
2234     * @syscap SystemCapability.Security.CryptoFramework
2235     * @since 10
2236     */
2237    generatePriKey(callback: AsyncCallback<PriKey>): void;
2238
2239    /**
2240     * Generate a private key instance.
2241     *
2242     * @returns { Promise<PriKey> } the promise used to return PriKey.
2243     * @throws { BusinessError } 401 - invalid parameters.
2244     * @throws { BusinessError } 17620001 - memory error.
2245     * @throws { BusinessError } 17630001 - crypto operation error.
2246     * @syscap SystemCapability.Security.CryptoFramework
2247     * @since 10
2248     */
2249    generatePriKey(): Promise<PriKey>;
2250
2251    /**
2252     * Generate a public key instance.
2253     *
2254     * @param { AsyncCallback<PubKey> } callback - the callback used to return PubKey.
2255     * @throws { BusinessError } 401 - invalid parameters.
2256     * @throws { BusinessError } 17620001 - memory error.
2257     * @throws { BusinessError } 17630001 - crypto operation error.
2258     * @syscap SystemCapability.Security.CryptoFramework
2259     * @since 10
2260     */
2261    generatePubKey(callback: AsyncCallback<PubKey>): void;
2262
2263    /**
2264     * Generate a public key instance.
2265     *
2266     * @returns { Promise<PubKey> } the promise used to return PubKey.
2267     * @throws { BusinessError } 401 - invalid parameters.
2268     * @throws { BusinessError } 17620001 - memory error.
2269     * @throws { BusinessError } 17630001 - crypto operation error.
2270     * @syscap SystemCapability.Security.CryptoFramework
2271     * @since 10
2272     */
2273    generatePubKey(): Promise<PubKey>;
2274
2275    /**
2276     * Indicates the algorithm name of the generator.
2277     *
2278     * @type { string }
2279     * @readonly
2280     * @syscap SystemCapability.Security.CryptoFramework
2281     * @since 10
2282     */
2283    readonly algName: string;
2284  }
2285
2286  /**
2287   * Create an asymmetric key generator with the specified parameters.
2288   *
2289   * @param { AsyKeySpec } asyKeySpec - indicates the associated parameters of algorithm.
2290   * @returns { AsyKeyGeneratorBySpec } the generator obj create by asyKeySpec.
2291   * @throws { BusinessError } 401 - invalid parameters.
2292   * @throws { BusinessError } 801 - this operation is not supported.
2293   * @throws { BusinessError } 17620001 - memory error.
2294   * @syscap SystemCapability.Security.CryptoFramework
2295   * @since 10
2296   */
2297  function createAsyKeyGeneratorBySpec(asyKeySpec: AsyKeySpec): AsyKeyGeneratorBySpec;
2298}
2299
2300export default cryptoFramework;
2301