harmony 鸿蒙Encryption and Decryption by Segment
Encryption and Decryption by Segment
The Crypto framework does not have a limit on the amount of the data to be passed in one time or cumulatively during the encryption/decryption process. However, when the amount of data is greater than 2 MB, you are advised to pass in and encrypt/decrypt the data by segment to improve processing efficiency.
Symmetric Encryption and Decryption
Use Cipher.update to pass in and encrypt/decrypt the data of a symmetric key by segment.
You can set the amount of the data to be passed in each time (updateLength in the example) and call update() multiple times to pass in the data.
Currently, the amount of data that can be passed in each time cannot exceed INT_MAX (maximum length of the Uint8Array type).
The value returned by each update and doFinal must be checked. If the return value is not null, obtain and combine the data segments into the complete ciphertext or plaintext.
Example: Encryption and Decryption by Segment with an AES Symmetric Key (GCM Mode)
Example: Encryption and Decryption by Segment with an SM4 Symmetric Key (GCM Mode)
Asymmetric Encryption and Decryption
Use Cipher.init and Cipher.doFinal to pass in and encrypt/decrypt the data of an asymmetric key pair by segment.
If the plaintext length is greater than the data length supported by a single encryption (see Asymmetric Key Encryption and Decryption Algorithm Specifications), divide the data to be encrypted into data segments of an appropriate length and encrypt each data segment. Specifically, create a Cipher instance and call Cipher.init and Cipher.doFinal.
The amount of data to be passed in each time varies, depending on the key specifications.
- RSA: The input data varies depending on the padding mode. Determine the amount of the data to be passed in at a time based on RSA specifications.
- SM2: The amount of the data to be encrypted must be of the fixed length. For details, see SM2.
The value returned by each doFinal must be checked. If the return value is not null, obtain and combine the data segments into the complete ciphertext or plaintext.
Example: Encryption and Decryption by Segment with an RSA Asymmetric Key Pair
FAQs
- Does the cipher mode affect the amount of the data to be passed in by each update in encryption and decryption by segment?
You can set the amount of the data to be passed in by each update. It has nothing to do with the cipher mode.
The encryption/decryption parameters vary with the cipher mode. For details, see ParamsSpec.
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Crypto Architecture Kit
harmony 鸿蒙Encryption and Decryption with a 3DES Symmetric Key (ECB Mode) (C/C++)
harmony 鸿蒙Encryption and Decryption with a 3DES Symmetric Key (ECB Mode) (ArkTS)
harmony 鸿蒙Encryption and Decryption with an AES Symmetric Key (CBC Mode) (C/C++)
harmony 鸿蒙Encryption and Decryption with an AES Symmetric Key (CBC Mode) (ArkTS)
harmony 鸿蒙Encryption and Decryption with an AES Symmetric Key (CCM Mode) (C/C++)
harmony 鸿蒙Encryption and Decryption with an AES Symmetric Key (CCM Mode) (ArkTS)
harmony 鸿蒙Encryption and Decryption with an AES Symmetric Key (ECB Mode) (C/C++)
harmony 鸿蒙Encryption and Decryption with an AES Symmetric Key (ECB Mode) (ArkTS)
harmony 鸿蒙Encryption and Decryption by Segment with an AES Symmetric Key (GCM Mode) (C/C++)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦