Module: Toybox::Cryptography

Overview

The Cryptography Module will allow the application to create a Cipher object that can encrypt and decrypt ByteArray objects.

Since:

  • 3.0.0

Defined Under Namespace

Classes: Cipher, CipherBasedMessageAuthenticationCode, Hash, HashBasedMessageAuthenticationCode, InvalidBlockSizeException, Key, KeyAgreement, KeyPair

Constant Summary

HASH_SHA1 = 0

SHA-1 implementation for Hash objects

See Also:

Since:

  • 3.0.0

HASH_SHA256 = 1

SHA-256 implementation for Hash objects

See Also:

Since:

  • 3.0.0

HASH_MD5 = 2

MD5 implementation for Hash objects

See Also:

Since:

  • 3.0.0

CIPHER_AES128 = 0

AES128 implementation for Cipher objects

CIPHER_AES256 = 1

AES256 implementation for Cipher objects

MODE_ECB = 0

Electronic Code Book (ECB)

This is the simplest encryption mode. Each plaintext block is directly encrypted into a ciphertext block, independent of any other block. This mode exposes frequency of symbols in your plaintext. Other modes (e.g. CBC) are recommended.

MODE_CBC = 1

Cipher-Block Chaining

Each ciphertext block depends on the current and all previous plaintext blocks. An Initialization Vector (IV) is required. The IV is a data block to be transmitted to the receiver. The IV can be made public, but it must be authenticated by the receiver and it should be picked randomly.

KEY_PAIR_ELLIPTIC_CURVE_SECP224R1 = 0

224-bit secp224r1 Elliptic Curve

Based on the algebraic structure of elliptic curves over finite fields. ECC requires smaller keys compared to non-ECC cryptography to provide equivalent security.

KEY_PAIR_ELLIPTIC_CURVE_SECP256R1 = 1

256-bit secp256r1 Elliptic Curve

Based on the algebraic structure of elliptic curves over finite fields. ECC requires smaller keys compared to non-ECC cryptography to provide equivalent security.

KEY_AGREEMENT_ECDH = 0

Elliptic Curve Diffie-Hellman (ECDH)

Instance Method Summary collapse

Instance Method Details

createPublicKey(algorithm, bytes) ⇒ Toybox::Cryptography::Key

Create a public Key object from bytes to be added to a KeyAgreement.

If a public key is received from another party, it can be converted to a Key object using this method.

Parameters:

Returns:

Raises:

Since:

  • 3.0.0


3749
3750
# File 'Monkeybrains.rb', line 3749

def createPublicKey(algorithm, bytes)
end

randomBytes(size) ⇒ Toybox::Lang::ByteArray

Generates cryptographically random bytes.

Parameters:

Returns:

Since:

  • 3.0.0


3832
3833
# File 'Monkeybrains.rb', line 3832

def randomBytes(size)
end