Class: BlockCipher

BlockCipher

Abstract class which provides base functionality used by all symmetric block cipher subclasses

<virtual> new BlockCipher()

NOTE: you can't instantiate this class directly. Instead, create instances of a subclass, such as AES or Twofish.
Source:

Requires

  • module:convert

Members

debug_mode :Boolean

Turn this on to enable the BlockCipher#debug_write method to log debug output to the console.
Type:
  • Boolean
Default Value:
  • false
Source:

Methods

debug_write(arguments)

Writes debug information to the console if BlockCipher#debug_mode is turned on.
Parameters:
Name Type Argument Description
arguments mixed <repeatable>
The variables to write to console
Source:

decrypt(ciphertext) → {String}

Decrypts a string.
Parameters:
Name Type Description
ciphertext String An ASCII string to decrypt.
Source:
Returns:
Encrypted data
Type
String

encrypt(plaintext) → {String}

Encrypts a string using the padding and block cipher mode of operation specificed on initialization.
Parameters:
Name Type Description
plaintext String An ASCII string to encrypt. Can be binary or plaintext. For plaintext, be sure to use convert.utf8.encode to encode any UTF characters.
Source:
Returns:
Decrypted data
Type
String

get_salt() → {String}

Gets the salt used for any passphrase-based key derivation.
Source:
Returns:
Type
String

initialize(data) → {BlockCipher}

Invoked during subclass initialization. All properties needed to initialize the class must be passed in.
Parameters:
Name Type Description
data Object A list of properties used to initialize the class.
Properties
Name Type Argument Default Description
key string <optional>
A binary string containing the symmetric key. Required if a passphrase is not specified. Must match a key length supported by the subclass.
block_mode BlockCipherMode <optional>
CBC The block cipher mode of operation to use for *cryption
pad_mode PaddingMode <optional>
PKCS7 The block byte padding mode
passphrase string <optional>
A passphrase to derive a key from. Required if a key is not explicitly specified.
salt string <optional>
A binary string containing the cryptographic salt used for key derivation.
openssl_mode boolean <optional>
false Toggles OpenSSL interoperability mode. This prepends salt data to the encryption output, and uses the prepended salt data during decryption to derive a key (in combination with a passphrase), if needed.
Source:
Returns:
Type
BlockCipher