Class: Toybox.Cryptography.Cipher

Overview

A Cipher object.

See Also:

Since:

API Level 3.0.0

Supported Devices:

Instance Method Summary collapse

Instance Method Details

decrypt(ciphertext as Lang.ByteArray) as Lang.ByteArray

Decrypt data with the key, depending on how the cipher was initialized.

Decryption can be broken up into two or more calls to decrypt(). For MODE_CBC, the ciphertext length (in bytes) must be a multiple of the block size.

Parameters:

Returns:

Since:

API Level 3.0.0

Throws:

encrypt(plaintext as Lang.ByteArray) as Lang.ByteArray

Encrypt data with the key, depending on how the cipher was initialized.

Encryption can be broken up into two or more calls to encrypt. For MODE_CBC, the plaintext length (in bytes) must be a multiple of the block size.

Parameters:

Returns:

Since:

API Level 3.0.0

Throws:

initialize(options as { :algorithm as Cryptography.CipherAlgorithm, :mode as Cryptography.EncryptionMode, :key as Lang.ByteArray, :iv as Lang.ByteArray })

Constructor

Parameters:

  • options(Lang.Dictionary)

    A Dictionary of options

    • :algorithm(Lang.Number)

      The encryption type this cipher object will use from the CIPHER_* enumeration (required)

    • :mode(Lang.Number)

      The encryption mode this cipher object will use from the MODE_* enumeration (required)

    • :key(Lang.ByteArray)

      The secret key to use in the cipher. The key must be of the appropriate length for the encryption type selected (required)

    • :iv(Lang.ByteArray)

      The initialization vector to use for encryption or decryption. This will be generated by the system using secure random bytes for algorithms that require it if it is not provided (optional)

Since:

API Level 3.0.0

Throws:

  • (Lang.UnexpectedTypeException)

    Thrown if a type other than ByteArray is provided for the :key and :iv options

  • (Lang.InvalidOptionsException)

    Thrown if a required option is not provided, the :algorithm and :mode options are not initialized with a valid enumeration, an invalid key size is provided for the selected algorithm, or an invalid initialization vector size is provided for the selected algorithm


Generated Apr 1, 2024 11:04:31 AM