Class: Toybox::Cryptography::Cipher

Inherits:
Lang::Object show all

Overview

A Cipher object.

See Also:

Since:

  • 3.0.0

Instance Method Summary collapse

Methods inherited from Lang::Object

equals, hashCode, method, toString, weak

Constructor Details

initialize(options) ⇒ Cipher

Returns a new instance of Cipher

Parameters:

Options Hash (options):

  • :algorithm (Toybox::Lang::Number)

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

  • :mode (Toybox::Lang::Number)

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

  • :key (Toybox::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 (Toybox::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)

Raises:

  • (Toybox::Lang::UnexpectedTypeException)

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

  • (Toybox::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

Since:

  • 3.0.0


3689
3690
# File 'Monkeybrains.rb', line 3689

def initialize(options)
end

Instance Method Details

decrypt(ciphertext) ⇒ Toybox::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:

Raises:

Since:

  • 3.0.0


3704
3705
# File 'Monkeybrains.rb', line 3704

def decrypt(ciphertext)
end

encrypt(plaintext) ⇒ Toybox::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:

Raises:

Since:

  • 3.0.0


3718
3719
# File 'Monkeybrains.rb', line 3718

def encrypt(plaintext)
end