目录

Encryption and Decryption of Symmetric Keys with AES-WRAP (ArkTS)

Starting from API version 22, the algorithm library supports encryption and decryption using this algorithm.

For the corresponding algorithm specifications, see AES-WRAP encryption and decryption algorithm specifications.

Encryption

  1. Call cryptoFramework.createSymKeyGenerator and SymKeyGenerator.convertKey to generate a 128-bit AES symmetric key (SymKey).

    For details about how to generate an AES symmetric key, refer to the following example and also see Symmetric Key Generation and Conversion Specifications: AES and Randomly Generating a Symmetric Key. The referenced documents may differ from the current example in input parameters. Pay attention to these differences when reading.

  2. Call cryptoFramework.createCipher and specify the string parameter AES128-WRAP to create a Cipher instance of the AES128-WRAP type for encryption.

  3. Call Cipher.init to initialize the Cipher instance. Specifically, set the mode to cryptoFramework.CryptoMode.ENCRYPT_MODE (encryption), key to SymKey (the key for encryption), and parameter to IvParamsSpec.

  4. To encrypt a small amount of data, simply call Cipher.doFinal.

Decryption

  1. Call cryptoFramework.createCipher and specify the string parameter AES128-WRAP to create a Cipher instance of the AES128-WRAP type for decryption.

  2. Call Cipher.init to initialize the Cipher instance. Specifically, set the mode to cryptoFramework.CryptoMode.DECRYPT_MODE (decryption), key to SymKey (the key for decryption), and parameter to IvParamsSpec.

  3. To decrypt a small amount of data, simply call Cipher.doFinal.