# securityå系统ChangeLog ## cl.security.1 对API9ä¸å·²ç»æŠ›å‡ºçš„异常,补写throwsæ ‡ç¾ å¯¹äºŽåœ¨API9ä¸å·²ç»æŠ›å‡ºå¼‚常而JS DOCä¸æ¼å†™throwsæ ‡ç¾çš„接å£ï¼Œåœ¨since 9的注释ä¸è¡¥ä¸Šthrowsæ ‡ç¾ã€‚ **å˜æ›´å½±å“** 对于已å‘布的JS接å£ï¼Œå¯èƒ½å½±å“异常处ç†æµç¨‹ï¼ŒåŒ…括åŒæ¥å¼‚常和异æ¥å¼‚常。应用需è¦æ ¹æ®æœ€æ–°çš„throwsæ ‡ç¾ï¼ŒæŽ’查是å¦æœ‰é—æ¼çš„异常处ç†æµç¨‹ï¼Œç»“åˆå®žé™…情况进行适é…。 **关键的接å£/组件å˜æ›´** 修改å‰çš„接å£åŽŸåž‹ï¼š ```ts interface Key { /** * Encode the key object to binary data. * * @returns { DataBlob } the binary data of the key object. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ getEncoded(): DataBlob; } interface AsyKeyGenerator { /** * Used to generate asymmetric key pair. * * @param { AsyncCallback<KeyPair> } callback - the callback used to return keypair. * @throws { BusinessError } 401 - invalid parameters. * @throws { BusinessError } 17620001 - memory error. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ generateKeyPair(callback: AsyncCallback<KeyPair>): void; /** * Used to generate asymmetric key pair. * * @returns { Promise<KeyPair> } the promise used to return keypair. * @throws { BusinessError } 401 - invalid parameters. * @throws { BusinessError } 17620001 - memory error. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ generateKeyPair(): Promise<KeyPair>; /** * Used to convert asymmetric key data to key pair object. * * @param { DataBlob } pubKey - the public key data blob. * @param { DataBlob } priKey - the private key data blob. * @param { AsyncCallback<KeyPair> } callback - the callback used to return keypair. * @throws { BusinessError } 401 - invalid parameters. * @throws { BusinessError } 17620001 - memory error. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ convertKey(pubKey: DataBlob, priKey: DataBlob, callback: AsyncCallback<KeyPair>): void; /** * Used to convert asymmetric key data to key pair object. * * @param { DataBlob } pubKey - the public key data blob. * @param { DataBlob } priKey - the private key data blob. * @returns { Promise<KeyPair> } the promise used to return keypair. * @throws { BusinessError } 401 - invalid parameters. * @throws { BusinessError } 17620001 - memory error. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ convertKey(pubKey: DataBlob, priKey: DataBlob): Promise<KeyPair>; } /** * Provides the asymmetric key generator instance func. * * @param { string } algName - indicates the algorithm name. * @returns { AsyKeyGenerator } the generator obj create by algName. * @throws { BusinessError } 401 - invalid parameters. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ function createAsyKeyGenerator(algName: string): AsyKeyGenerator; /** * Create a cipher object for encryption and decryption operations according to the given specifications. * Two different Cipher objects should be created when using RSA encryption and decryption, * even with the same specifications. * * @param { string } transformation - indicates the description to be transformed to cipher specifications. * @returns { Cipher } the cipher object returned by the function. * @throws { BusinessError } 401 - invalid parameters. * @throws { BusinessError } 801 - this operation is not supported. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ function createCipher(transformation: string): Cipher; /** * Create sign class. * * @param { string } algName - indicates the algorithm name and params. * @returns { Sign } the sign class. * @throws { BusinessError } 401 - invalid parameters. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ function createSign(algName: string): Sign; /** * Create verify class. * * @param { string } algName - indicates the algorithm name and params. * @returns { Verify } the verify class. * @throws { BusinessError } 401 - invalid parameters. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ function createVerify(algName: string): Verify; /** * Create key agreement class. * * @param { string } algName - indicates the algorithm name and params. * @returns { KeyAgreement } the key agreement class. * @throws { BusinessError } 401 - invalid parameters. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ function createKeyAgreement(algName: string): KeyAgreement; ``` 修改åŽçš„接å£åŽŸåž‹ï¼š ```ts interface Key { /** * Encode the key object to binary data. * * @returns { DataBlob } the binary data of the key object. * @throws { BusinessError } 801 - this operation is not supported. * @throws { BusinessError } 17620001 - memory error. * @throws { BusinessError } 17630001 - crypto operation error. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ getEncoded(): DataBlob; } interface AsyKeyGenerator { /** * Used to generate asymmetric keypair. * * @param { AsyncCallback<KeyPair> } callback - the callback used to return keypair. * @throws { BusinessError } 401 - invalid parameters. * @throws { BusinessError } 17620001 - memory error. * @throws { BusinessError } 17630001 - crypto operation error. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ generateKeyPair(callback: AsyncCallback<KeyPair>): void; /** * Used to generate asymmetric keypair. * * @returns { Promise<KeyPair> } the promise used to return keypair. * @throws { BusinessError } 401 - invalid parameters. * @throws { BusinessError } 17620001 - memory error. * @throws { BusinessError } 17630001 - crypto operation error. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ generateKeyPair(): Promise<KeyPair>; /** * Used to convert asymmetric key data to keypair object. * * @param { DataBlob } pubKey - the public key data blob. * @param { DataBlob } priKey - the private key data blob. * @param { AsyncCallback<KeyPair> } callback - the callback used to return keypair. * @throws { BusinessError } 401 - invalid parameters. * @throws { BusinessError } 17620001 - memory error. * @throws { BusinessError } 17630001 - crypto operation error. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ convertKey(pubKey: DataBlob, priKey: DataBlob, callback: AsyncCallback<KeyPair>): void; /** * Used to convert asymmetric key data to keypair object. * * @param { DataBlob } pubKey - the public key data blob. * @param { DataBlob } priKey - the private key data blob. * @returns { Promise<KeyPair> } the promise used to return keypair. * @throws { BusinessError } 401 - invalid parameters. * @throws { BusinessError } 17620001 - memory error. * @throws { BusinessError } 17630001 - crypto operation error. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ convertKey(pubKey: DataBlob, priKey: DataBlob): Promise<KeyPair>; } /** * Create the asymmetric key generator instance according to the given algorithm name. * * @param { string } algName - indicates the algorithm name. * @returns { AsyKeyGenerator } the asymmetric key generator instance. * @throws { BusinessError } 401 - invalid parameters. * @throws { BusinessError } 801 - this operation is not supported. * @throws { BusinessError } 17620001 - memory error. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ function createAsyKeyGenerator(algName: string): AsyKeyGenerator; /** * Create a cipher object for encryption and decryption operations according to the given specifications. * Two different Cipher objects should be created when using RSA encryption and decryption, * even with the same specifications. * * @param { string } transformation - indicates the description to be transformed to cipher specifications. * @returns { Cipher } the cipher object returned by the function. * @throws { BusinessError } 401 - invalid parameters. * @throws { BusinessError } 801 - this operation is not supported. * @throws { BusinessError } 17620001 - memory error. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ function createCipher(transformation: string): Cipher; /** * Create a sign object for generating signatures. * * @param { string } algName - indicates the algorithm name and params. * @returns { Sign } the sign class. * @throws { BusinessError } 401 - invalid parameters. * @throws { BusinessError } 801 - this operation is not supported. * @throws { BusinessError } 17620001 - memory error. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ function createSign(algName: string): Sign; /** * Create a verify object for verifying signatures. * * @param { string } algName - indicates the algorithm name and the parameters. * @returns { Verify } the verify class. * @throws { BusinessError } 401 - invalid parameters. * @throws { BusinessError } 801 - this operation is not supported. * @throws { BusinessError } 17620001 - memory error. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ function createVerify(algName: string): Verify; /** * Create a key agreement object. * * @param { string } algName - indicates the algorithm name and params. * @returns { KeyAgreement } the key agreement object. * @throws { BusinessError } 401 - invalid parameters. * @throws { BusinessError } 801 - this operation is not supported. * @throws { BusinessError } 17620001 - memory error. * @syscap SystemCapability.Security.CryptoFramework * @since 9 */ function createKeyAgreement(algName: string): KeyAgreement; ``` **适é…指导** 由于æ¼æ ‡çš„throws异常å‘生在较少è§çš„情况下,应用å¯ä»¥ç»“åˆå®žé™…情况,排查æ¼æ ‡çš„throwsæ ‡ç¾æ˜¯å¦éœ€è¦ä¸“门适é…。 - 对于åŒæ¥æ–¹æ³•ï¼Œå¦‚createSignç‰ï¼Œè¯·ä½¿ç”¨try/catchæ–¹å¼å¤„ç†é”™è¯¯ä¿¡æ¯ã€‚ - 对于异æ¥æ–¹æ³•ï¼Œå¦‚convertKeyç‰ï¼Œè¯·ä½¿ç”¨try/catchæ–¹å¼å¤„ç†åŒæ¥çš„å‚数错误,使用error对象的方å¼èŽ·å–异æ¥çš„å‚数错误和业务执行错误。