# Text hashing and ciphering reference

Hasher

The `Hasher` class is a base class that is used to build a message hash. The hash result is stored in an array of bytes and can be retrieved byte by byte or as a formatted printable string. This class does not have a constructor.

hasher-p
Object
get-name
String
none

The `get-name` method return the hash algorithm name.

hash-p
Boolean
String

The `hash-p` predicate returns true if the string argument is potentially a hash value. It is not possible, with our current technology, to reverse a hash value to one or several representations, nor it is possible to assert that such value exists.

get-hash
Character
Integer

The `get-hash` method returns the hash byte value by index. The argument is the byte index which must be in the range of the hash algorithm result value.

format
String
none

The `format` method return a string representation of the hash value.

compute
String
Literal|Buffer|Input

The `compute` method computes the hash value from a string, a buffer or an input stream. The method returns a string representation of the result hash value.

Md5

The `Md5` class is a hashing class that implements the MD-5 algorithm.

md5-p
Hasher
Md5
none

The `Md5` constructor creates a default hashing object that implements the MD-5 algorithm.

Sha1

The `Sha1` class is a hashing class that implements the SHA-1 algorithm.

sha1-p
Hasher
Sha1
none

The `Sha1` constructor creates a default hashing object that implements the SHA-1 algorithm.

Sha256

The `Sha256` class is a hashing class that implements the SHA-256 algorithm.

sha256-p
Hasher
Sha256
none

The `Sha256` constructor creates a default hashing object that implements the SHA-256 algorithm.

Sha384

The `Sha384` class is a hashing class that implements the SHA-384 algorithm.

sha384-p
Hasher
Sha384
none

The `Sha384` constructor creates a default hashing object that implements the SHA-384 algorithm.

Sha512

The `Sha512` class is a hashing class that implements the SHA-512 algorithm.

sha512-p
Hasher
Sha512
none

The `Sha512` constructor creates a default hashing object that implements the SHA-512 algorithm.

Key

The `Key` class is a cipher key class that generates random key or message key. The key generation algorithm is based on the SHA-256 algorithm and accept different size. The default key size is 128 bits.

key-p
Object
Key
none

The `Key` constructor creates a default cipher key. The key is generated with random bytes and is 128 bits long.

Key
K128|K192|K256

The `Key` constructor creates a random cipher key by type. The argument is the key type which specify the key size.

Key
String

The `Key` constructor creates a message cipher key those size is 128 bits long. The first argument is the message to be used for the key generation.

Key
K128|K192|K256 String

The `Key` constructor creates a message cipher key by type. The first argument is the key type which specifies the key size. The second argument is the message to be used for the key generation.

K128

The `K128` constant indicates that the key is a 128 bits key.

K192

The `K192` constant indicates that the key is a 192 bits key.

K256

The `K256` constant indicates that the key is a 256 bits key.

get
Character
Integer

The `get` method returns a key character by index. The index must be in the key range or an exception is raised.

format
String
none

The `format` method returns a string representation of the key. Each byte is represented with its equivalent string representation.

get-type
Item
none

The `get-type` method returns the key type in the form of an item object. The item object is associated with the key object and the key size constant. The item can be used in key constructor.

get-size
Integer
none

The `get-size` method returns the key size in bytes.

Cipher

The `Cipher` class is a base class that is used to implement a symmetric block cipher. A reverse flag controls the cipher operation. When false, the cipher operates in encrypt mode. When true, the cipher operates in decrypt mode, that is the reverse mode. This class cannot be instantiated by itself.

cipher-p
Object
reset
none
none

The `reset` method reset the cipher internal state.

stream
Integer
Output Input

The `stream` method process an input stream and write into an output stream. The method returns the number of character processed. The first argument is the output stream used to write the coded characters. The second argument is the input stream used to read the characters.

set-key
none
Key

The `set-key` method sets the cipher key. The first argument is the key to set.

get-key
Key
none

The `get-key` method returns the cipher key.

get-name
String
none

The `get-name` method returns the cipher standard name.

get-size
Integer
none

The `get-size` method returns the cipher block size.

set-reverse
none
Boolean

The `set-reverse` method sets the cipher reverse flag. The first argument is the flag to set. If the flag is true, the cipher operates in reverse mode. If the flag is false, the cipher operates in direct mode.

get-reverse
Boolean
none

The `get-reverse` method returns the cipher reverse flag. If the flag is true, the cipher operates in reverse mode. If the flag is false, the cipher operates in direct mode.

Aes

The `Aes` class is a cipher class that implements the advanced encryption standard or AES block cipher. The AES cipher is a symmetric block cipher.

aes-p
Cipher
Aes
Key

The `Aes` constructor creates a direct cipher with a key. The first argument is the key used by the cipher.

Aes
Key Boolean

The `Aes` constructor creates a cipher with a key and a reverse flag. The first argument is the key used by the cipher. The second argument is the reverse flag.

InputCipher

The `InputCipher` class is an stream interface that can stream out an input stream from a cipher. In other word, an input stream is read and block are encoded as long as the input stream read characters. If the cipher is nil, the input cipher simply read the input stream and is therefore transparent. The class acts like an input stream, read the character from the bounded input stream and encode or decode them from the bounded cipher. The `InputCipher` defines two modes of operations. In electronic codebook mode or ECB, the character are encoded in a block basis. In cipher block chaining mode, the block are encoded by doing an XOR operation with the previous block. In all cases, a block padding is added, following the recommendation of RFC 2630 and NIST 800-38A.

input-cipher-p
Input
InputCipher
Cipher

The `InputCipher` constructor creates an input cipher with a cipher object. The first argument is the cipher to used for processing.

InputCipher
Cipher Input

The `InputCipher` constructor creates an input cipher with a cipher object and an input stream. The first argument is the cipher to used for processing. The second argument is the input stream object used for the character reading.

InputCipher
Cipher Input ECB|CBC

The `InputCipher` constructor creates an input cipher with a cipher object, an input stream and a mode. The first argument is the cipher to used for processing. The second argument is the input stream object used for the character reading. The third argument is the input cipher mode which can be either ECB or CBC.

ECB

The `ECB` constant indicates that the input cipher is to operate in electronic codebook mode. This mode is the default mode.

CBC

The `CBC` constant indicates that the input cipher is to operate in cipher chaining block mode.

set-is
none
Input

The `set-is` method sets the input cipher input stream. This method can be used to chain multiple input streams in a unique coding session.

dup
InputCipher
Input

The `dup` method duplicate the input cipher by binding the same input stream parameter and attaching the input stream argument. This method is particularly useful with `InputMapped` stream.