1e41f4b71Sopenharmony_ci# security子系统ChangeLog 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## cl.security.1 对API9中已经抛出的异常,补写throws标签 4e41f4b71Sopenharmony_ci对于在API9中已经抛出异常而JS DOC中漏写throws标签的接口,在since 9的注释中补上throws标签。 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci**变更影响** 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci对于已发布的JS接口,可能影响异常处理流程,包括同步异常和异步异常。应用需要根据最新的throws标签,排查是否有遗漏的异常处理流程,结合实际情况进行适配。 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci**关键的接口/组件变更** 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci修改前的接口原型: 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci ```ts 15e41f4b71Sopenharmony_ciinterface Key { 16e41f4b71Sopenharmony_ci /** 17e41f4b71Sopenharmony_ci * Encode the key object to binary data. 18e41f4b71Sopenharmony_ci * 19e41f4b71Sopenharmony_ci * @returns { DataBlob } the binary data of the key object. 20e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 21e41f4b71Sopenharmony_ci * @since 9 22e41f4b71Sopenharmony_ci */ 23e41f4b71Sopenharmony_ci getEncoded(): DataBlob; 24e41f4b71Sopenharmony_ci} 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ciinterface AsyKeyGenerator { 27e41f4b71Sopenharmony_ci /** 28e41f4b71Sopenharmony_ci * Used to generate asymmetric key pair. 29e41f4b71Sopenharmony_ci * 30e41f4b71Sopenharmony_ci * @param { AsyncCallback<KeyPair> } callback - the callback used to return keypair. 31e41f4b71Sopenharmony_ci * @throws { BusinessError } 401 - invalid parameters. 32e41f4b71Sopenharmony_ci * @throws { BusinessError } 17620001 - memory error. 33e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 34e41f4b71Sopenharmony_ci * @since 9 35e41f4b71Sopenharmony_ci */ 36e41f4b71Sopenharmony_ci generateKeyPair(callback: AsyncCallback<KeyPair>): void; 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci /** 39e41f4b71Sopenharmony_ci * Used to generate asymmetric key pair. 40e41f4b71Sopenharmony_ci * 41e41f4b71Sopenharmony_ci * @returns { Promise<KeyPair> } the promise used to return keypair. 42e41f4b71Sopenharmony_ci * @throws { BusinessError } 401 - invalid parameters. 43e41f4b71Sopenharmony_ci * @throws { BusinessError } 17620001 - memory error. 44e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 45e41f4b71Sopenharmony_ci * @since 9 46e41f4b71Sopenharmony_ci */ 47e41f4b71Sopenharmony_ci generateKeyPair(): Promise<KeyPair>; 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci /** 50e41f4b71Sopenharmony_ci * Used to convert asymmetric key data to key pair object. 51e41f4b71Sopenharmony_ci * 52e41f4b71Sopenharmony_ci * @param { DataBlob } pubKey - the public key data blob. 53e41f4b71Sopenharmony_ci * @param { DataBlob } priKey - the private key data blob. 54e41f4b71Sopenharmony_ci * @param { AsyncCallback<KeyPair> } callback - the callback used to return keypair. 55e41f4b71Sopenharmony_ci * @throws { BusinessError } 401 - invalid parameters. 56e41f4b71Sopenharmony_ci * @throws { BusinessError } 17620001 - memory error. 57e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 58e41f4b71Sopenharmony_ci * @since 9 59e41f4b71Sopenharmony_ci */ 60e41f4b71Sopenharmony_ci convertKey(pubKey: DataBlob, priKey: DataBlob, callback: AsyncCallback<KeyPair>): void; 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci /** 63e41f4b71Sopenharmony_ci * Used to convert asymmetric key data to key pair object. 64e41f4b71Sopenharmony_ci * 65e41f4b71Sopenharmony_ci * @param { DataBlob } pubKey - the public key data blob. 66e41f4b71Sopenharmony_ci * @param { DataBlob } priKey - the private key data blob. 67e41f4b71Sopenharmony_ci * @returns { Promise<KeyPair> } the promise used to return keypair. 68e41f4b71Sopenharmony_ci * @throws { BusinessError } 401 - invalid parameters. 69e41f4b71Sopenharmony_ci * @throws { BusinessError } 17620001 - memory error. 70e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 71e41f4b71Sopenharmony_ci * @since 9 72e41f4b71Sopenharmony_ci */ 73e41f4b71Sopenharmony_ci convertKey(pubKey: DataBlob, priKey: DataBlob): Promise<KeyPair>; 74e41f4b71Sopenharmony_ci} 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci/** 77e41f4b71Sopenharmony_ci * Provides the asymmetric key generator instance func. 78e41f4b71Sopenharmony_ci * 79e41f4b71Sopenharmony_ci * @param { string } algName - indicates the algorithm name. 80e41f4b71Sopenharmony_ci * @returns { AsyKeyGenerator } the generator obj create by algName. 81e41f4b71Sopenharmony_ci * @throws { BusinessError } 401 - invalid parameters. 82e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 83e41f4b71Sopenharmony_ci * @since 9 84e41f4b71Sopenharmony_ci */ 85e41f4b71Sopenharmony_cifunction createAsyKeyGenerator(algName: string): AsyKeyGenerator; 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci/** 88e41f4b71Sopenharmony_ci * Create a cipher object for encryption and decryption operations according to the given specifications. 89e41f4b71Sopenharmony_ci * Two different Cipher objects should be created when using RSA encryption and decryption, 90e41f4b71Sopenharmony_ci * even with the same specifications. 91e41f4b71Sopenharmony_ci * 92e41f4b71Sopenharmony_ci * @param { string } transformation - indicates the description to be transformed to cipher specifications. 93e41f4b71Sopenharmony_ci * @returns { Cipher } the cipher object returned by the function. 94e41f4b71Sopenharmony_ci * @throws { BusinessError } 401 - invalid parameters. 95e41f4b71Sopenharmony_ci * @throws { BusinessError } 801 - this operation is not supported. 96e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 97e41f4b71Sopenharmony_ci * @since 9 98e41f4b71Sopenharmony_ci */ 99e41f4b71Sopenharmony_cifunction createCipher(transformation: string): Cipher; 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci/** 102e41f4b71Sopenharmony_ci * Create sign class. 103e41f4b71Sopenharmony_ci * 104e41f4b71Sopenharmony_ci * @param { string } algName - indicates the algorithm name and params. 105e41f4b71Sopenharmony_ci * @returns { Sign } the sign class. 106e41f4b71Sopenharmony_ci * @throws { BusinessError } 401 - invalid parameters. 107e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 108e41f4b71Sopenharmony_ci * @since 9 109e41f4b71Sopenharmony_ci */ 110e41f4b71Sopenharmony_cifunction createSign(algName: string): Sign; 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci/** 113e41f4b71Sopenharmony_ci * Create verify class. 114e41f4b71Sopenharmony_ci * 115e41f4b71Sopenharmony_ci * @param { string } algName - indicates the algorithm name and params. 116e41f4b71Sopenharmony_ci * @returns { Verify } the verify class. 117e41f4b71Sopenharmony_ci * @throws { BusinessError } 401 - invalid parameters. 118e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 119e41f4b71Sopenharmony_ci * @since 9 120e41f4b71Sopenharmony_ci */ 121e41f4b71Sopenharmony_cifunction createVerify(algName: string): Verify; 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci/** 124e41f4b71Sopenharmony_ci * Create key agreement class. 125e41f4b71Sopenharmony_ci * 126e41f4b71Sopenharmony_ci * @param { string } algName - indicates the algorithm name and params. 127e41f4b71Sopenharmony_ci * @returns { KeyAgreement } the key agreement class. 128e41f4b71Sopenharmony_ci * @throws { BusinessError } 401 - invalid parameters. 129e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 130e41f4b71Sopenharmony_ci * @since 9 131e41f4b71Sopenharmony_ci */ 132e41f4b71Sopenharmony_cifunction createKeyAgreement(algName: string): KeyAgreement; 133e41f4b71Sopenharmony_ci ``` 134e41f4b71Sopenharmony_ci修改后的接口原型: 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci ```ts 137e41f4b71Sopenharmony_ciinterface Key { 138e41f4b71Sopenharmony_ci /** 139e41f4b71Sopenharmony_ci * Encode the key object to binary data. 140e41f4b71Sopenharmony_ci * 141e41f4b71Sopenharmony_ci * @returns { DataBlob } the binary data of the key object. 142e41f4b71Sopenharmony_ci * @throws { BusinessError } 801 - this operation is not supported. 143e41f4b71Sopenharmony_ci * @throws { BusinessError } 17620001 - memory error. 144e41f4b71Sopenharmony_ci * @throws { BusinessError } 17630001 - crypto operation error. 145e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 146e41f4b71Sopenharmony_ci * @since 9 147e41f4b71Sopenharmony_ci */ 148e41f4b71Sopenharmony_ci getEncoded(): DataBlob; 149e41f4b71Sopenharmony_ci} 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ciinterface AsyKeyGenerator { 152e41f4b71Sopenharmony_ci /** 153e41f4b71Sopenharmony_ci * Used to generate asymmetric keypair. 154e41f4b71Sopenharmony_ci * 155e41f4b71Sopenharmony_ci * @param { AsyncCallback<KeyPair> } callback - the callback used to return keypair. 156e41f4b71Sopenharmony_ci * @throws { BusinessError } 401 - invalid parameters. 157e41f4b71Sopenharmony_ci * @throws { BusinessError } 17620001 - memory error. 158e41f4b71Sopenharmony_ci * @throws { BusinessError } 17630001 - crypto operation error. 159e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 160e41f4b71Sopenharmony_ci * @since 9 161e41f4b71Sopenharmony_ci */ 162e41f4b71Sopenharmony_ci generateKeyPair(callback: AsyncCallback<KeyPair>): void; 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci /** 165e41f4b71Sopenharmony_ci * Used to generate asymmetric keypair. 166e41f4b71Sopenharmony_ci * 167e41f4b71Sopenharmony_ci * @returns { Promise<KeyPair> } the promise used to return keypair. 168e41f4b71Sopenharmony_ci * @throws { BusinessError } 401 - invalid parameters. 169e41f4b71Sopenharmony_ci * @throws { BusinessError } 17620001 - memory error. 170e41f4b71Sopenharmony_ci * @throws { BusinessError } 17630001 - crypto operation error. 171e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 172e41f4b71Sopenharmony_ci * @since 9 173e41f4b71Sopenharmony_ci */ 174e41f4b71Sopenharmony_ci generateKeyPair(): Promise<KeyPair>; 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci /** 177e41f4b71Sopenharmony_ci * Used to convert asymmetric key data to keypair object. 178e41f4b71Sopenharmony_ci * 179e41f4b71Sopenharmony_ci * @param { DataBlob } pubKey - the public key data blob. 180e41f4b71Sopenharmony_ci * @param { DataBlob } priKey - the private key data blob. 181e41f4b71Sopenharmony_ci * @param { AsyncCallback<KeyPair> } callback - the callback used to return keypair. 182e41f4b71Sopenharmony_ci * @throws { BusinessError } 401 - invalid parameters. 183e41f4b71Sopenharmony_ci * @throws { BusinessError } 17620001 - memory error. 184e41f4b71Sopenharmony_ci * @throws { BusinessError } 17630001 - crypto operation error. 185e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 186e41f4b71Sopenharmony_ci * @since 9 187e41f4b71Sopenharmony_ci */ 188e41f4b71Sopenharmony_ci convertKey(pubKey: DataBlob, priKey: DataBlob, callback: AsyncCallback<KeyPair>): void; 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci /** 191e41f4b71Sopenharmony_ci * Used to convert asymmetric key data to keypair object. 192e41f4b71Sopenharmony_ci * 193e41f4b71Sopenharmony_ci * @param { DataBlob } pubKey - the public key data blob. 194e41f4b71Sopenharmony_ci * @param { DataBlob } priKey - the private key data blob. 195e41f4b71Sopenharmony_ci * @returns { Promise<KeyPair> } the promise used to return keypair. 196e41f4b71Sopenharmony_ci * @throws { BusinessError } 401 - invalid parameters. 197e41f4b71Sopenharmony_ci * @throws { BusinessError } 17620001 - memory error. 198e41f4b71Sopenharmony_ci * @throws { BusinessError } 17630001 - crypto operation error. 199e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 200e41f4b71Sopenharmony_ci * @since 9 201e41f4b71Sopenharmony_ci */ 202e41f4b71Sopenharmony_ci convertKey(pubKey: DataBlob, priKey: DataBlob): Promise<KeyPair>; 203e41f4b71Sopenharmony_ci} 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ci/** 206e41f4b71Sopenharmony_ci * Create the asymmetric key generator instance according to the given algorithm name. 207e41f4b71Sopenharmony_ci * 208e41f4b71Sopenharmony_ci * @param { string } algName - indicates the algorithm name. 209e41f4b71Sopenharmony_ci * @returns { AsyKeyGenerator } the asymmetric key generator instance. 210e41f4b71Sopenharmony_ci * @throws { BusinessError } 401 - invalid parameters. 211e41f4b71Sopenharmony_ci * @throws { BusinessError } 801 - this operation is not supported. 212e41f4b71Sopenharmony_ci * @throws { BusinessError } 17620001 - memory error. 213e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 214e41f4b71Sopenharmony_ci * @since 9 215e41f4b71Sopenharmony_ci */ 216e41f4b71Sopenharmony_cifunction createAsyKeyGenerator(algName: string): AsyKeyGenerator; 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci/** 219e41f4b71Sopenharmony_ci * Create a cipher object for encryption and decryption operations according to the given specifications. 220e41f4b71Sopenharmony_ci * Two different Cipher objects should be created when using RSA encryption and decryption, 221e41f4b71Sopenharmony_ci * even with the same specifications. 222e41f4b71Sopenharmony_ci * 223e41f4b71Sopenharmony_ci * @param { string } transformation - indicates the description to be transformed to cipher specifications. 224e41f4b71Sopenharmony_ci * @returns { Cipher } the cipher object returned by the function. 225e41f4b71Sopenharmony_ci * @throws { BusinessError } 401 - invalid parameters. 226e41f4b71Sopenharmony_ci * @throws { BusinessError } 801 - this operation is not supported. 227e41f4b71Sopenharmony_ci * @throws { BusinessError } 17620001 - memory error. 228e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 229e41f4b71Sopenharmony_ci * @since 9 230e41f4b71Sopenharmony_ci */ 231e41f4b71Sopenharmony_cifunction createCipher(transformation: string): Cipher; 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci/** 234e41f4b71Sopenharmony_ci * Create a sign object for generating signatures. 235e41f4b71Sopenharmony_ci * 236e41f4b71Sopenharmony_ci * @param { string } algName - indicates the algorithm name and params. 237e41f4b71Sopenharmony_ci * @returns { Sign } the sign class. 238e41f4b71Sopenharmony_ci * @throws { BusinessError } 401 - invalid parameters. 239e41f4b71Sopenharmony_ci * @throws { BusinessError } 801 - this operation is not supported. 240e41f4b71Sopenharmony_ci * @throws { BusinessError } 17620001 - memory error. 241e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 242e41f4b71Sopenharmony_ci * @since 9 243e41f4b71Sopenharmony_ci */ 244e41f4b71Sopenharmony_cifunction createSign(algName: string): Sign; 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci/** 247e41f4b71Sopenharmony_ci * Create a verify object for verifying signatures. 248e41f4b71Sopenharmony_ci * 249e41f4b71Sopenharmony_ci * @param { string } algName - indicates the algorithm name and the parameters. 250e41f4b71Sopenharmony_ci * @returns { Verify } the verify class. 251e41f4b71Sopenharmony_ci * @throws { BusinessError } 401 - invalid parameters. 252e41f4b71Sopenharmony_ci * @throws { BusinessError } 801 - this operation is not supported. 253e41f4b71Sopenharmony_ci * @throws { BusinessError } 17620001 - memory error. 254e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 255e41f4b71Sopenharmony_ci * @since 9 256e41f4b71Sopenharmony_ci */ 257e41f4b71Sopenharmony_cifunction createVerify(algName: string): Verify; 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ci/** 260e41f4b71Sopenharmony_ci * Create a key agreement object. 261e41f4b71Sopenharmony_ci * 262e41f4b71Sopenharmony_ci * @param { string } algName - indicates the algorithm name and params. 263e41f4b71Sopenharmony_ci * @returns { KeyAgreement } the key agreement object. 264e41f4b71Sopenharmony_ci * @throws { BusinessError } 401 - invalid parameters. 265e41f4b71Sopenharmony_ci * @throws { BusinessError } 801 - this operation is not supported. 266e41f4b71Sopenharmony_ci * @throws { BusinessError } 17620001 - memory error. 267e41f4b71Sopenharmony_ci * @syscap SystemCapability.Security.CryptoFramework 268e41f4b71Sopenharmony_ci * @since 9 269e41f4b71Sopenharmony_ci */ 270e41f4b71Sopenharmony_cifunction createKeyAgreement(algName: string): KeyAgreement; 271e41f4b71Sopenharmony_ci ``` 272e41f4b71Sopenharmony_ci 273e41f4b71Sopenharmony_ci**适配指导** 274e41f4b71Sopenharmony_ci 275e41f4b71Sopenharmony_ci由于漏标的throws异常发生在较少见的情况下,应用可以结合实际情况,排查漏标的throws标签是否需要专门适配。 276e41f4b71Sopenharmony_ci 277e41f4b71Sopenharmony_ci- 对于同步方法,如createSign等,请使用try/catch方式处理错误信息。 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci- 对于异步方法,如convertKey等,请使用try/catch方式处理同步的参数错误,使用error对象的方式获取异步的参数错误和业务执行错误。 280