• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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 {AsyncCallback, Callback} from './basic';
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 * @namespace cryptoFramework
22 * @syscap SystemCapability.Security.CryptoFramework
23 * @since 9
24 */
25declare namespace cryptoFramework {
26    /**
27     * Enum for result code.
28     * @enum {number}
29     * @syscap SystemCapability.Security.CryptoFramework
30     * @since 9
31     */
32    enum Result {
33        /** Indicates that input parameters is invalid.
34         * @since 9
35         */
36        INVALID_PARAMS = 401,
37
38        /** Indicates that function or algorithm is not supported.
39         * @since 9
40         */
41        NOT_SUPPORT = 801,
42
43        /** Indicates the memory error.
44         * @since 9
45         */
46        ERR_OUT_OF_MEMORY = 17620001,
47
48        /** Indicates that runtime error.
49         * @since 9
50         */
51        ERR_RUNTIME_ERROR = 17620002,
52
53        /** Indicates that crypto operation error.
54         * @since 9
55         */
56        ERR_CRYPTO_OPERATION = 17630001,
57    }
58
59    /**
60     * Provides the data blob type.
61     * @typedef DataBlob
62     * @syscap SystemCapability.Security.CryptoFramework
63     * @since 9
64     */
65    interface DataBlob {
66        data : Uint8Array;
67    }
68
69    /**
70     * Provides the ParamsSpec type, including the algorithm name.
71     * @typedef ParamsSpec
72     * @syscap SystemCapability.Security.CryptoFramework
73     * @since 9
74     */
75    interface ParamsSpec {
76        /**
77         * Indicates the algorithm name. Should be set before initialization of a cipher object.
78         * @type { string }
79         * @syscap SystemCapability.Security.CryptoFramework
80         * @since 9
81         */
82        algName : string;
83    }
84
85    /**
86     * Provides the IvParamsSpec type, including the parameter iv.
87     * @typedef IvParamsSpec
88     * @syscap SystemCapability.Security.CryptoFramework
89     * @since 9
90     */
91    interface IvParamsSpec extends ParamsSpec {
92        /**
93         * Indicates the algorithm parameters such as iv.
94         * @type { DataBlob }
95         * @syscap SystemCapability.Security.CryptoFramework
96         * @since 9
97         */
98        iv : DataBlob;
99    }
100
101    /**
102     * Provides the GcmParamsSpec type, including the parameter iv, aad and authTag.
103     * @typedef GcmParamsSpec
104     * @syscap SystemCapability.Security.CryptoFramework
105     * @since 9
106     */
107    interface GcmParamsSpec extends ParamsSpec {
108        /**
109         * Indicates the GCM algorithm parameters such as iv.
110         * @type { DataBlob }
111         * @syscap SystemCapability.Security.CryptoFramework
112         * @since 9
113         */
114        iv : DataBlob;
115
116        /**
117         * Indicates the additional Authenticated Data in GCM mode.
118         * @type { DataBlob }
119         * @syscap SystemCapability.Security.CryptoFramework
120         * @since 9
121         */
122        aad : DataBlob;
123
124        /**
125         * Indicates the output tag from the encryption operation. The tag is used for integrity check.
126         * @type { DataBlob }
127         * @syscap SystemCapability.Security.CryptoFramework
128         * @since 9
129         */
130        authTag : DataBlob;
131    }
132
133    /**
134     * Provides the CcmParamsSpec type, including the parameter iv, aad and authTag.
135     * @typedef CcmParamsSpec
136     * @syscap SystemCapability.Security.CryptoFramework
137     * @since 9
138     */
139    interface CcmParamsSpec extends ParamsSpec {
140        /**
141         * Indicates the GCM algorithm parameters such as IV.
142         * @type { DataBlob }
143         * @syscap SystemCapability.Security.CryptoFramework
144         * @since 9
145         */
146        iv : DataBlob;
147
148        /**
149         * Indicates the Additional Authenticated Data in CCM mode.
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         * @type { DataBlob }
159         * @syscap SystemCapability.Security.CryptoFramework
160         * @since 9
161         */
162        authTag : DataBlob;
163    }
164
165    /**
166     * Enum for obtain the crypto operation.
167     * @enum { number }
168     * @syscap SystemCapability.Security.CryptoFramework
169     * @since 9
170     */
171    enum CryptoMode {
172        /**
173         * The value of encryption operation for AES, 3DES and RSA.
174         * @syscap SystemCapability.Security.CryptoFramework
175         * @since 9
176         */
177        ENCRYPT_MODE = 0,
178
179        /**
180         * The value of decryption operation for AES, 3DES and RSA.
181         * @syscap SystemCapability.Security.CryptoFramework
182         * @since 9
183         */
184        DECRYPT_MODE = 1,
185    }
186
187    /**
188     * Provides the Key type, which is the common parent class of keys.
189     * @typedef Key
190     * @syscap SystemCapability.Security.CryptoFramework
191     * @since 9
192     */
193    interface Key {
194        /**
195         * Encode the key object to binary data.
196         * @returns { DataBlob } the binary data of the key object.
197         * @syscap SystemCapability.Security.CryptoFramework
198         * @since 9
199         */
200        getEncoded() : DataBlob;
201
202        /**
203         * Indicates the format of the key object.
204         * @type { string }
205         * @readonly
206         * @syscap SystemCapability.Security.CryptoFramework
207         * @since 9
208         */
209        readonly format : string;
210
211        /**
212         * Indicates the algorithm name of the key object.
213         * @type { string }
214         * @readonly
215         * @syscap SystemCapability.Security.CryptoFramework
216         * @since 9
217         */
218        readonly algName : string;
219    }
220
221    /**
222     * Provides the SymKey type, which is used for symmetric cryptography.
223     * @typedef SymKey
224     * @syscap SystemCapability.Security.CryptoFramework
225     * @since 9
226     */
227    interface SymKey extends Key {
228        /**
229         * Reset the key data to zero in the memory.
230         * @syscap SystemCapability.Security.CryptoFramework
231         * @since 9
232         */
233        clearMem() : void;
234    }
235
236    /**
237     * Provides the private key type.
238     * @typedef PriKey
239     * @syscap SystemCapability.Security.CryptoFramework
240     * @since 9
241     */
242    interface PriKey extends Key {
243
244        /**
245         * Clear memory of private key.
246         * @syscap SystemCapability.Security.CryptoFramework
247         * @since 9
248         */
249        clearMem() : void;
250    }
251
252    /**
253     * The public key class of asymmetrical key.
254     * @typedef PubKey
255     * @syscap SystemCapability.Security.CryptoFramework
256     * @since 9
257     */
258    interface PubKey extends Key {}
259
260    /**
261     * The keyPair class of  asymmetrical key. Include privateKey and publickey.
262     * @typedef KeyPair
263     * @syscap SystemCapability.Security.CryptoFramework
264     * @since 9
265     */
266    interface KeyPair {
267
268        /**
269         * KeyPair's private key.
270         * @type { PriKey }
271         * @readonly
272         * @syscap SystemCapability.Security.CryptoFramework
273         * @since 9
274         */
275        readonly priKey : PriKey;
276
277        /**
278         * KeyPair's public key.
279         * @type { PubKey }
280         * @readonly
281         * @syscap SystemCapability.Security.CryptoFramework
282         * @since 9
283         */
284        readonly pubKey : PubKey;
285    }
286
287    /**
288     * Provides the random interface.
289     * @typedef Random
290     * @syscap SystemCapability.Security.CryptoFramework
291     * @since 9
292     */
293    interface Random {
294        /**
295         * Generate random DataBlob by given length.
296         * @param len Indicates the length of random DataBlob.
297         * @returns Returns the generated random blob.
298         * @throws { BusinessError } 401 - invalid parameters.
299         * @throws { BusinessError } 17620001 - memory error.
300         * @throws { BusinessError } 17630001 - crypto operation error.
301         * @syscap SystemCapability.Security.CryptoFramework
302         * @since 9
303         */
304        generateRandom(len : number, callback: AsyncCallback<DataBlob>) : void;
305        generateRandom(len : number) : Promise<DataBlob>;
306
307        /**
308         * Set seed by given DataBlob.
309         * @param seed Indicates the seed DataBlob.
310         * @throws { BusinessError } 17620001 - memory error.
311         * @syscap SystemCapability.Security.CryptoFramework
312         * @since 9
313         */
314        setSeed(seed : DataBlob) : void;
315    }
316
317    /**
318     * Provides the rand create func.
319     * @returns Returns the created rand instance.
320     * @throws { BusinessError } 17620001 - memory error.
321     * @syscap SystemCapability.Security.CryptoFramework
322     * @since 9
323     */
324    function createRandom() : Random;
325
326    /**
327     * The AsyKeyGenerator provides the ability to generate or convert keyPair.
328     * @typedef AsyKeyGenerator
329     * @syscap SystemCapability.Security.CryptoFramework
330     * @since 9
331     */
332     interface AsyKeyGenerator {
333        /**
334         * Used to generate asymmetric key pair.
335         * @param { AsyncCallback<KeyPair> } callback - the callback used to return keypair.
336         * @throws { BusinessError } 401 - invalid parameters.
337         * @throws { BusinessError } 17620001 - memory error.
338         * @syscap SystemCapability.Security.CryptoFramework
339         * @since 9
340         */
341        generateKeyPair(callback : AsyncCallback<KeyPair>) : void;
342
343        /**
344         * Used to generate asymmetric key pair.
345         * @returns { Promise<KeyPair> } - the promise used to return keypair.
346         * @throws { BusinessError } 401 - invalid parameters.
347         * @throws { BusinessError } 17620001 - memory error.
348         * @syscap SystemCapability.Security.CryptoFramework
349         * @since 9
350         */
351        generateKeyPair() : Promise<KeyPair>;
352
353        /**
354         * Used to convert asymmetric key pair .
355         * @param { DataBlob } pubKey - the public key data blob.
356         * @param { DataBlob } priKey - the private key data blob.
357         * @param { AsyncCallback<KeyPair> } callback - the callback used to return keypair.
358         * @throws { BusinessError } 401 - invalid parameters.
359         * @throws { BusinessError } 17620001 - memory error.
360         * @syscap SystemCapability.Security.CryptoFramework
361         * @since 9
362         */
363        convertKey(pubKey : DataBlob, priKey : DataBlob, callback : AsyncCallback<KeyPair>) : void;
364
365        /**
366         * Used to convert asymmetric key pair.
367         * @param { DataBlob } pubKey - the public key data blob.
368         * @param { DataBlob } priKey - the private key data blob.
369         * @returns { promise<KeyPair> } - the promise used to return keypair.
370         * @throws { BusinessError } 401 - invalid parameters.
371         * @throws { BusinessError } 17620001 - memory error.
372         * @syscap SystemCapability.Security.CryptoFramework
373         * @since 9
374         */
375        convertKey(pubKey : DataBlob, priKey : DataBlob) : Promise<KeyPair>;
376
377        /**
378         * The algName of the AsyKeyGenerator.
379         * @type { string }
380         * @syscap SystemCapability.Security.CryptoFramework
381         * @readonly
382         * @since 9
383         */
384        readonly algName : string;
385    }
386
387    /**
388     * Provides the SymKeyGenerator type, which is used for generating symmetric key.
389     * @typedef SymKeyGenerator
390     * @syscap SystemCapability.Security.CryptoFramework
391     * @since 9
392     */
393    interface SymKeyGenerator {
394        /**
395         * Generate a symmetric key object randomly.
396         * @param { AsyncCallback<SymKey> } callback - the callback of generateSymKey.
397         * @throws { BusinessError } 17620001 - memory error.
398         * @syscap SystemCapability.Security.CryptoFramework
399         * @since 9
400         */
401        generateSymKey(callback : AsyncCallback<SymKey>) : void;
402
403        /**
404         * Generate a symmetric key object randomly.
405         * @returns { Promise<SymKey> } the promise returned by the function.
406         * @throws { BusinessError } 17620001 - memory error.
407         * @syscap SystemCapability.Security.CryptoFramework
408         * @since 9
409         */
410        generateSymKey() : Promise<SymKey>;
411
412        /**
413         * Generate a symmetric key object according to the provided binary key data.
414         * @param { AsyncCallback<SymKey> } callback - the callback of generateSymKey.
415         * @throws { BusinessError } 401 - invalid parameters.
416         * @throws { BusinessError } 17620001 - memory error.
417         * @syscap SystemCapability.Security.CryptoFramework
418         * @since 9
419         */
420        convertKey(key : DataBlob, callback : AsyncCallback<SymKey>) : void;
421
422        /**
423         * Generate a symmetric key object according to the provided binary key data.
424         * @returns { Promise<SymKey> } the promise returned by the function.
425         * @throws { BusinessError } 401 - invalid parameters.
426         * @throws { BusinessError } 17620001 - memory error.
427         * @syscap SystemCapability.Security.CryptoFramework
428         * @since 9
429         */
430        convertKey(key : DataBlob) : Promise<SymKey>;
431
432        /**
433         * Indicates the algorithm name of the SymKeyGenerator object.
434         * @type { string }
435         * @readonly
436         * @syscap SystemCapability.Security.CryptoFramework
437         * @since 9
438         */
439        readonly algName : string;
440    }
441
442    /**
443     * Provides the asymmetrical key generator instance func.
444     * @param { string } algName Indicates the algorithm name.
445     * @returns {AsyKeyGenerator} the generator obj create by algName.
446     * @throws { BusinessError } 401 - invalid parameters.
447     * @syscap SystemCapability.Security.CryptoFramework
448     * @since 9
449     */
450    function createAsyKeyGenerator(algName : string) : AsyKeyGenerator;
451
452    /**
453     * Create a symmetric key generator according to the given algorithm name.
454     * @param { string } algName - indicates the algorithm name.
455     * @returns { SymKeyGenerator } the symmetric key generator instance.
456     * @throws { BusinessError } 401 - invalid parameters.
457     * @throws { BusinessError } 801 - this operation is not supported.
458     * @syscap SystemCapability.Security.CryptoFramework
459     * @since 9
460     */
461    function createSymKeyGenerator(algName : string) : SymKeyGenerator;
462
463    interface Mac {
464        /**
465         * Init hmac with given SymKey.
466         * @param key Indicates the SymKey.
467         * @throws { BusinessError } 401 - invalid parameters.
468         * @throws { BusinessError } 17630001 - crypto operation error.
469         * @syscap SystemCapability.Security.CryptoFramework
470         * @since 9
471         */
472        init(key : SymKey, callback : AsyncCallback<void>) : void;
473        init(key : SymKey) : Promise<void>;
474
475        /**
476         * Update hmac with DataBlob.
477         * @param input Indicates the DataBlob.
478         * @throws { BusinessError } 401 - invalid parameters.
479         * @throws { BusinessError } 17630001 - crypto operation error.
480         * @syscap SystemCapability.Security.CryptoFramework
481         * @since 9
482         */
483        update(input : DataBlob, callback : AsyncCallback<void>) : void;
484        update(input : DataBlob) : Promise<void>;
485
486        /**
487         * Output the result of hmac calculation.
488         * @throws { BusinessError } 17620001 - memory error.
489         * @throws { BusinessError } 17630001 - crypto operation error.
490         * @syscap SystemCapability.Security.CryptoFramework
491         * @since 9
492         */
493        doFinal(callback : AsyncCallback<DataBlob>) : void;
494        doFinal() : Promise<DataBlob>;
495
496        /**
497         * Output the length of hmac result.
498         * @returns Returns the length of the hmac result.
499         * @throws { BusinessError } 17630001 - crypto operation error.
500         * @syscap SystemCapability.Security.CryptoFramework
501         * @since 9
502         */
503        getMacLength() : number;
504
505        /**
506         * Indicates the algorithm name.
507         * @type { string }
508         * @readonly
509         * @syscap SystemCapability.Security.CryptoFramework
510         * @since 9
511         */
512        readonly algName : string;
513    }
514
515    /**
516     * Provides the mac create func.
517     * @param algName Indicates the mac algorithm name.
518     * @returns Returns the created mac instance.
519     * @throws { BusinessError } 401 - invalid parameters.
520     * @throws { BusinessError } 17620001 - memory error.
521     * @syscap SystemCapability.Security.CryptoFramework
522     * @since 9
523     */
524    function createMac(algName : string) : Mac;
525
526    interface Md {
527        /**
528         * Update md with DataBlob.
529         * @param input Indicates the DataBlob.
530         * @throws { BusinessError } 401 - invalid parameters.
531         * @throws { BusinessError } 17630001 - crypto operation error.
532         * @syscap SystemCapability.Security.CryptoFramework
533         * @since 9
534         */
535        update(input : DataBlob, callback : AsyncCallback<void>) : void;
536        update(input : DataBlob) : Promise<void>;
537
538        /**
539         * Output the result of md calculation.
540         * @returns Returns the calculated hmac result.
541         * @throws { BusinessError } 17620001 - memory error.
542         * @throws { BusinessError } 17630001 - crypto operation error.
543         * @syscap SystemCapability.Security.CryptoFramework
544         * @since 9
545         */
546        digest(callback : AsyncCallback<DataBlob>) : void;
547        digest() : Promise<DataBlob>;
548
549        /**
550         * Output the length of md result.
551         * @returns Returns the length of the hmac result.
552         * @throws { BusinessError } 17630001 - crypto operation error.
553         * @syscap SystemCapability.Security.CryptoFramework
554         * @since 9
555         */
556        getMdLength() : number;
557
558        /**
559         * Indicates the algorithm name.
560         * @type { string }
561         * @readonly
562         * @syscap SystemCapability.Security.CryptoFramework
563         * @since 9
564         */
565        readonly algName : string;
566    }
567
568    /**
569     * Provides the md create func.
570     * @param algName Indicates the md algorithm name.
571     * @returns Returns the created md instance.
572     * @throws { BusinessError } 401 - invalid parameters.
573     * @throws { BusinessError } 17620001 - memory error.
574     * @syscap SystemCapability.Security.CryptoFramework
575     * @since 9
576     */
577    function createMd(algName : string) : Md;
578
579    /**
580     * Provides the Cipher type, which is used for encryption and decryption operations.
581     * @typedef Cipher
582     * @syscap SystemCapability.Security.CryptoFramework
583     * @since 9
584     */
585    interface Cipher {
586        /**
587         * Init the crypto operation with the given crypto mode, key and parameters.
588         * @param { CryptoMode } opMode - indicates the crypto mode is encryption or decryption.
589         * @param { Key } key - indicates the symmetric key or the asymmetric key.
590         * @param { ParamsSpec } params - indicates the algorithm parameters such as IV.
591         * @param { AsyncCallback<void> } callback - the callback of the init function.
592         * @throws { BusinessError } 401 - invalid parameters.
593         * @throws { BusinessError } 17620001 - memory error.
594         * @throws { BusinessError } 17620002 - runtime error.
595         * @throws { BusinessError } 17630001 - crypto operation error.
596         * @syscap SystemCapability.Security.CryptoFramework
597         * @since 9
598         */
599        init(opMode : CryptoMode, key : Key, params : ParamsSpec, callback : AsyncCallback<void>) : void;
600
601        /**
602         * Init the crypto operation with the given crypto mode, key and parameters.
603         * @param { CryptoMode } opMode - indicates the crypto mode is encryption or decryption.
604         * @param { Key } key - indicates the symmetric key or the asymmetric key.
605         * @param { ParamsSpec } params - indicates the algorithm parameters such as IV.
606         * @returns { Promise<void> } the promise returned by the function.
607         * @throws { BusinessError } 401 - invalid parameters.
608         * @throws { BusinessError } 17620001 - memory error.
609         * @throws { BusinessError } 17620002 - runtime error.
610         * @throws { BusinessError } 17630001 - crypto operation error.
611         * @syscap SystemCapability.Security.CryptoFramework
612         * @since 9
613         */
614        init(opMode : CryptoMode, key : Key, params : ParamsSpec) : Promise<void>;
615
616        /**
617         * Update the crypto operation with the input data, and feed back the encrypted or decrypted data
618         * this time. RSA is not supported in this function.
619         * @param { DataBlob } data - indicates the data to be encrypted or decrypted.
620         * @param { AsyncCallback<DataBlob> } callback - the callback of the update function.
621         * @throws { BusinessError } 401 - invalid parameters.
622         * @throws { BusinessError } 17620001 - memory error.
623         * @throws { BusinessError } 17620002 - runtime error.
624         * @throws { BusinessError } 17630001 - crypto operation error.
625         * @syscap SystemCapability.Security.CryptoFramework
626         * @since 9
627         */
628        update(data : DataBlob, callback : AsyncCallback<DataBlob>) : void;
629
630        /**
631         * Update the crypto operation with the input data, and feed back the encrypted or decrypted data
632         * this time. RSA is not supported in this function.
633         * @param { DataBlob } data - indicates the data to be encrypted or decrypted.
634         * @returns { Promise<DataBlob> } the promise returned by the function.
635         * @throws { BusinessError } 401 - invalid parameters.
636         * @throws { BusinessError } 17620001 - memory error.
637         * @throws { BusinessError } 17620002 - runtime error.
638         * @throws { BusinessError } 17630001 - crypto operation error.
639         * @syscap SystemCapability.Security.CryptoFramework
640         * @since 9
641         */
642        update(data : DataBlob) : Promise<DataBlob>;
643
644        /**
645         * Finish the crypto operation, encrypt or decrypt the input data, and then feed back the output data.
646         * Data cannot be updated after the crypto operation is finished.
647         * @param { DataBlob } data - indicates the data to be finally encrypted or decrypted.
648         * @param { AsyncCallback<DataBlob> } callback - the callback of the doFinal function.
649         * @throws { BusinessError } 401 - invalid parameters.
650         * @throws { BusinessError } 17620001 - memory error.
651         * @throws { BusinessError } 17620002 - runtime error.
652         * @throws { BusinessError } 17630001 - crypto operation error.
653         * @syscap SystemCapability.Security.CryptoFramework
654         * @since 9
655         */
656        doFinal(data : DataBlob, callback : AsyncCallback<DataBlob>) : void;
657
658        /**
659         * Finish the crypto operation, encrypt or decrypt the input data, and then feed back the output data.
660         * Data cannot be updated after the crypto operation is finished.
661         * @param { DataBlob } data - indicates the data to be finally encrypted or decrypted.
662         * @returns { Promise<DataBlob> } the promise returned by the function.
663         * @throws { BusinessError } 401 - invalid parameters.
664         * @throws { BusinessError } 17620001 - memory error.
665         * @throws { BusinessError } 17620002 - runtime error.
666         * @throws { BusinessError } 17630001 - crypto operation error.
667         * @syscap SystemCapability.Security.CryptoFramework
668         * @since 9
669         */
670        doFinal(data : DataBlob) : Promise<DataBlob>;
671
672        /**
673         * Indicates the algorithm name of the Cipher object.
674         * @type { string }
675         * @readonly
676         * @syscap SystemCapability.Security.CryptoFramework
677         * @since 9
678         */
679        readonly algName : string;
680    }
681
682    /**
683     * Create a cipher object for encryption and decryption operations according to the given specifications.
684     * Two different Cipher objects should be created when using RSA encryption and decryption,
685     * even with the same specifications.
686     * @param { string } transformation - Indicates the description to be transformed to cipher specifications.
687     * @returns { Cipher } the cipher object returned by the function.
688     * @throws { BusinessError } 401 - invalid parameters.
689     * @throws { BusinessError } 801 - this operation is not supported.
690     * @syscap SystemCapability.Security.CryptoFramework
691     * @since 9
692     */
693    function createCipher(transformation : string) : Cipher;
694
695    /**
696     * Provides sign function.
697     * @typedef Sign
698     * @syscap SystemCapability.Security.CryptoFramework
699     * @since 9
700     */
701    interface Sign {
702        /**
703         * Used to init environment.
704         * @param { PriKey } priKey - the private key.
705         * @param { AsyncCallback<void> } callback - return nothing.
706         * @throws { BusinessError } 401 - invalid parameters.
707         * @throws { BusinessError } 17620001 - memory error.
708         * @throws { BusinessError } 17620002 - runtime error.
709         * @throws { BusinessError } 17630001 - crypto operation error.
710         * @syscap SystemCapability.Security.CryptoFramework
711         * @since 9
712         */
713        init(priKey : PriKey, callback : AsyncCallback<void>) : void;
714
715         /**
716         * Used to init environment.
717         * @param { PriKey } priKey - the private key.
718         * @returns { promise<void> } - return nothing.
719         * @throws { BusinessError } 401 - invalid parameters.
720         * @throws { BusinessError } 17620001 - memory error.
721         * @throws { BusinessError } 17620002 - runtime error.
722         * @throws { BusinessError } 17630001 - crypto operation error.
723         * @syscap SystemCapability.Security.CryptoFramework
724         * @since 9
725         */
726        init(priKey : PriKey) : Promise<void>;
727
728        /**
729         * Used to append the message need to be signed.
730         * @param { DataBlob } data - the data need to be signed.
731         * @param { AsyncCallback<void> } callback - return nothing.
732         * @throws { BusinessError } 401 - invalid parameters.
733         * @throws { BusinessError } 17620001 - memory error.
734         * @throws { BusinessError } 17620002 - runtime error.
735         * @throws { BusinessError } 17630001 - crypto operation error.
736         * @syscap SystemCapability.Security.CryptoFramework
737         * @since 9
738         */
739        update(data : DataBlob, callback : AsyncCallback<void>) : void;
740
741        /**
742         * Used to append the message need to be signed.
743         * @param { DataBlob } data - the data need to be signed.
744         * @returns { promise<void> } - return nothing.
745         * @throws { BusinessError } 401 - invalid parameters.
746         * @throws { BusinessError } 17620001 - memory error.
747         * @throws { BusinessError } 17620002 - runtime error.
748         * @throws { BusinessError } 17630001 - crypto operation error.
749         * @syscap SystemCapability.Security.CryptoFramework
750         * @since 9
751         */
752        update(data : DataBlob) : Promise<void>;
753
754        /**
755         * Used to sign message, include the update data.
756         * @param { DataBlob } data - the data need to be signed.
757         * @param { AsyncCallback<DataBlob> } callback - return the signed message.
758         * @throws { BusinessError } 401 - invalid parameters.
759         * @throws { BusinessError } 17620001 - memory error.
760         * @throws { BusinessError } 17620002 - runtime error.
761         * @throws { BusinessError } 17630001 - crypto operation error.
762         * @syscap SystemCapability.Security.CryptoFramework
763         * @since 9
764         */
765        sign(data : DataBlob, callback : AsyncCallback<DataBlob>) : void;
766
767        /**
768         * Used to append the message need to be signed.
769         * @param { DataBlob } data - the private key.
770         * @returns { promise<DataBlob> } - return the signed message.
771         * @throws { BusinessError } 401 - invalid parameters.
772         * @throws { BusinessError } 17620001 - memory error.
773         * @throws { BusinessError } 17620002 - runtime error.
774         * @throws { BusinessError } 17630001 - crypto operation error.
775         * @syscap SystemCapability.Security.CryptoFramework
776         * @since 9
777         */
778        sign(data : DataBlob) : Promise<DataBlob>;
779
780        /**
781         * The sign algName.
782         * @type { string }
783         * @syscap SystemCapability.Security.CryptoFramework
784         * @readonly
785         * @since 9
786         */
787        readonly algName : string;
788    }
789
790    /**
791     * Provides verify function.
792     * @typedef Verify
793     * @syscap SystemCapability.Security.CryptoFramework
794     * @since 9
795     */
796    interface Verify {
797        /**
798         * Used to init environment.
799         * @param { PubKey } pubKey - the public key.
800         * @param { AsyncCallback<void> } callback - return nothing.
801         * @throws { BusinessError } 401 - invalid parameters.
802         * @throws { BusinessError } 17620001 - memory error.
803         * @throws { BusinessError } 17620002 - runtime error.
804         * @throws { BusinessError } 17630001 - crypto operation error.
805         * @syscap SystemCapability.Security.CryptoFramework
806         * @since 9
807         */
808        init(pubKey : PubKey, callback : AsyncCallback<void>) : void;
809
810        /**
811         * Used to init environment.
812         * @param { PubKey } pubKey - the public key.
813         * @returns { promise<void> } - return nothing.
814         * @throws { BusinessError } 401 - invalid parameters.
815         * @throws { BusinessError } 17620001 - memory error.
816         * @throws { BusinessError } 17620002 - runtime error.
817         * @throws { BusinessError } 17630001 - crypto operation error.
818         * @syscap SystemCapability.Security.CryptoFramework
819         * @since 9
820         */
821        init(pubKey : PubKey) : Promise<void>;
822
823        /**
824         * Used to append the message need to be verified.
825         * @param { DataBlob } data - the data need to be verified.
826         * @param { AsyncCallback<void> } callback - return nothing.
827         * @throws { BusinessError } 401 - invalid parameters.
828         * @throws { BusinessError } 17620001 - memory error.
829         * @throws { BusinessError } 17620002 - runtime error.
830         * @throws { BusinessError } 17630001 - crypto operation error.
831         * @syscap SystemCapability.Security.CryptoFramework
832         * @since 9
833         */
834        update(data : DataBlob, callback : AsyncCallback<void>) : void;
835
836        /**
837         * Used to append the message need to be verified.
838         * @param { DataBlob } data - the data need to be verified.
839         * @returns { promise<void> } - return nothing.
840         * @throws { BusinessError } 401 - invalid parameters.
841         * @throws { BusinessError } 17620001 - memory error.
842         * @throws { BusinessError } 17620002 - runtime error.
843         * @throws { BusinessError } 17630001 - crypto operation error.
844         * @syscap SystemCapability.Security.CryptoFramework
845         * @since 9
846         */
847        update(data : DataBlob) : Promise<void>;
848
849        /**
850         * Used to verify message, include the update data.
851         * @param { DataBlob } data - the data need to be verified.
852         * @param { DataBlob } signatureData - the signature data.
853         * @param { AsyncCallback<boolean> } callback - return the verify result.
854         * @throws { BusinessError } 401 - invalid parameters.
855         * @throws { BusinessError } 17620001 - memory error.
856         * @throws { BusinessError } 17620002 - runtime error.
857         * @throws { BusinessError } 17630001 - crypto operation error.
858         * @syscap SystemCapability.Security.CryptoFramework
859         * @since 9
860         */
861        verify(data : DataBlob, signatureData : DataBlob, callback : AsyncCallback<boolean>) : void;
862
863        /**
864         * Used to verify message, include the update data.
865         * @param { DataBlob } data - the data need to be verified.
866         * @param { DataBlob } signatureData - the signature data.
867         * @returns { Promise<boolean> } callback - return the verify result.
868         * @throws { BusinessError } 401 - invalid parameters.
869         * @throws { BusinessError } 17620001 - memory error.
870         * @throws { BusinessError } 17620002 - runtime error.
871         * @throws { BusinessError } 17630001 - crypto operation error.
872         * @syscap SystemCapability.Security.CryptoFramework
873         * @since 9
874         */
875        verify(data : DataBlob, signatureData : DataBlob) : Promise<boolean>;
876
877        /**
878         * Indicates the verify algorithm name.
879         * @type { string }
880         * @readonly
881         * @syscap SystemCapability.Security.CryptoFramework
882         * @since 9
883         */
884        readonly algName : string;
885    }
886
887    /**
888     * Create sign class.
889     * @param { string } algName - Indicates the algorithm name and params.
890     * @returns { Sign } the sign class.
891     * @throws { BusinessError } 401 - invalid parameters.
892     * @syscap SystemCapability.Security.CryptoFramework
893     * @since 9
894     */
895    function createSign(algName : string) : Sign;
896
897     /**
898      * Create verify class.
899      * @param { string } algName - Indicates the algorithm name and params.
900      * @returns { Verify } the verify class.
901      * @throws { BusinessError } 401 - invalid parameters.
902      * @syscap SystemCapability.Security.CryptoFramework
903      * @since 9
904      */
905     function createVerify(algName : string) : Verify;
906
907    /**
908     * Provides key agreement function.
909     * @typedef KeyAgreement
910     * @syscap SystemCapability.Security.CryptoFramework
911     * @since 9
912     */
913     interface KeyAgreement {
914        /**
915         * Used to generate secret.
916         * @param { PriKey } priKey - the private key.
917         * @param { PubKey } pubKey - the public key.
918         * @param { AsyncCallback<DataBlob> } callback - return the secret.
919         * @throws { BusinessError } 401 - invalid parameters.
920         * @throws { BusinessError } 17620001 - memory error.
921         * @throws { BusinessError } 17620002 - runtime error.
922         * @throws { BusinessError } 17630001 - crypto operation error.
923         * @syscap SystemCapability.Security.CryptoFramework
924         * @since 9
925         */
926        generateSecret(priKey : PriKey, pubKey : PubKey, callback : AsyncCallback<DataBlob>) : void;
927
928        /**
929         * Used to generate secret.
930         * @param { PriKey } priKey - the private key.
931         * @param { PubKey } pubKey - the public key.
932         * @returns { Promise<DataBlob> } the promise used to return secret.
933         * @throws { BusinessError } 401 - invalid parameters.
934         * @throws { BusinessError } 17620001 - memory error.
935         * @throws { BusinessError } 17620002 - runtime error.
936         * @throws { BusinessError } 17630001 - crypto operation error.
937         * @syscap SystemCapability.Security.CryptoFramework
938         * @since 9
939         */
940        generateSecret(priKey : PriKey, pubKey : PubKey) : Promise<DataBlob>;
941
942        /**
943         * Indicates the algorithm name.
944         * @type { string }
945         * @readonly
946         * @syscap SystemCapability.Security.CryptoFramework
947         * @since 9
948         */
949        readonly algName : string;
950    }
951
952    /**
953     * Create key agreement class.
954     * @param { string } algName - Indicates the algorithm name and params.
955     * @returns { KeyAgreement } the key agreement class.
956     * @throws { BusinessError } 401 - invalid parameters.
957     * @syscap SystemCapability.Security.CryptoFramework
958     * @since 9
959     */
960    function createKeyAgreement(algName : string) : KeyAgreement;
961}
962
963export default cryptoFramework;
964