sodium

The popular salt-based cryptographic library from libsodium.
Specializing in cryptographic practices for security various types of data.
All data created by this library is formatted in hexadecimal for memory safety.


Functions

sodium.random(min: number, max: number, alpha?: boolean): string

sodium.random(min: number, max: number, alpha?: boolean): string
  • Creates a randomly generated string.
  • If alpha is true then strings will be alphabets rather than hexadecimal.

Hex

Hexadecimal (or "hex") is a base-16 number system commonly used to represent binary data in a compact form.

sodium.hex.encode(input: string): string

sodium.hex.encode(input: string): string
  • Converts data into it's hexadecimal form.

sodium.hex.decode(input: string): string

sodium.hex.decode(input: string): string
  • Converts hexadecimal formatted data into it's original data.

Base64

Base64 is a method of encoding binary data into an ASCII string using a fixed-size alphabet, which makes it easier to transmit or store the data over media that are designed to deal with textual data.

sodium.base64.encode(input: string): string

sodium.base64.encode(input: string): string
  • Converts data into it's base64 form.

sodium.base64.decode(input: string): string

sodium.base64.decode(input: string): string
  • Converts base64 formatted data into it's original data.

sodium.base64.xencode(input: string): string

sodium.base64.xencode(input: string): string
  • Converts hexadecimal formatted data into it's base64 form.

sodium.base64.xdecode(input: string): string

sodium.base64.xdecode(input: string): string
  • Converts base64 formatted data into it's hexadecimal form.

HASH

Cryptographic hash function that provides data integrity by creating a unique "fingerprint" of the input data.
Not generally considered a cipher in the traditional sense, but rather a building block for various cryptographic protocols and algorithms.

sodium.hash.enc256(input: string): string

sodium.hash.enc256(input: string): string
  • Creates a SHA-256 block hash based on the input data.

sodium.hash.enc512(input: string): string

sodium.hash.enc512(input: string): string
  • Creates a SHA-512 block hash based on the input data.

HMAC

HMAC (Hash-based Message Authentication Code) is a type of message authentication code that provides both authenticity and integrity by using a cryptographic hash function in combination with a secret key to produce a "tag" that verifies the message.

sodium.hmac.key256(): string

sodium.hmac.key256(): string
  • Creates a HMAC-256 cipher key.

sodium.hmac.enc256(input: string, key: string): string

sodium.hmac.enc256(input: string, key: string): string
  • Creates a HMAC-256 block hash based on the input data.

sodium.hmac.key512(): string

sodium.hmac.key512(): string
  • Creates a HMAC-512 cipher key.

sodium.hmac.enc512(input: string, key: string): string

sodium.hmac.enc512(input: string, key: string): string
  • Creates a HMAC-512 block hash based on the input data.

sodium.hmac.key512256(): string

sodium.hmac.key512256(): string
  • Creates a HMAC-512256 cipher key.

sodium.hmac.enc512256(input: string, key: string): string

sodium.hmac.enc512256(input: string, key: string): string
  • Creates a HMAC-512256 block hash based on the input data.

Signature

Digital signatures are used to provide authenticity and integrity of a cipher message.
They use public-key cryptography and a hash function to create a unique digital signature that can be used to verify the authenticity and integrity of the message.

sodium.signature.key(): string, string

sodium.signature.key(): string, string
  • Creates a two-pair signature key.
  • Return in order of "Public Key" and "Secret Key".

sodium.signature.encode(input: string, sk: string): string

sodium.signature.encode(input: string, sk: string): string
  • Encodes a message with the secret key.

sodium.signature.decode(input: string, pk: string): string

sodium.signature.decode(input: string, pk: string): string
  • Decodes a message with the public key.

AEAD

Authenticated Encryption with Associated Data (AEAD) is a type of encryption algorithm that provides both confidentiality and authenticity for data.

ChaCha20Poly1305

An authenticated encryption algorithm that uses the ChaCha stream cipher for encryption and the Poly1305 message authentication code.

sodium.aead.chachapoly.nonce(): string

sodium.aead.chachapoly.nonce(): string
  • Generates a nonce which is used in securing uniqueness.

sodium.aead.chachapoly.key(base?: string, salt?: string): string

sodium.aead.chachapoly.key(base?: string, salt?: string): string
  • Generates a key, providing a base acts as an offset, with providing a salt for greater resiliance.

sodium.aead.chachapoly.encrypt(input: string, key: string, nonce: string): string

sodium.aead.chachapoly.encrypt(input: string, key: string, nonce: string): string
  • Encrypts a messages based on the key and added nonce.

sodium.aead.chachapoly.decrypt(input: string, key: string, nonce: string): string

sodium.aead.chachapoly.decrypt(input: string, key: string, nonce: string): string
  • Decrypts a messages based on the key and added nonce.

sodium.aead.chachapoly.encode(input: string, key: string): string

sodium.aead.chachapoly.encode(input: string, key: string): string
  • Encrypts a message based on the key, this generates its own nonce internally.
  • The nonce is applied to the start of the message.

sodium.aead.chachapoly.decode(input: string, key: string): string

sodium.aead.chachapoly.decode(input: string, key: string): string
  • Decrypts a message based on the key, this handles its own nonce internally.
  • The nonce is applied to the start of the message.

GCM-256

A block cipher mode of operation called Galois/Counter Mode (GCM) that provides both confidentiality and authenticity, using a 256-bit key.

sodium.aead.gcm.nonce(): string

sodium.aead.gcm.nonce(): string
  • Generates a nonce which is used in securing uniqueness.

sodium.aead.gcm.key(base?: string, salt?: string): string

sodium.aead.gcm.key(base?: string, salt?: string): string
  • Generates a key, providing a base acts as an offset, with providing a salt for greater resiliance.

sodium.aead.gcm.encrypt(input: string, key: string, nonce: string): string

sodium.aead.gcm.encrypt(input: string, key: string, nonce: string): string
  • Encrypts a messages based on the key and added nonce.

sodium.aead.gcm.decrypt(input: string, key: string, nonce: string): string

sodium.aead.gcm.decrypt(input: string, key: string, nonce: string): string
  • Decrypts a messages based on the key and added nonce.

sodium.aead.gcm.encode(input: string, key: string): string

sodium.aead.gcm.encode(input: string, key: string): string
  • Encrypts a message based on the key, this generates its own nonce internally.
  • The nonce is applied to the start of the message.

sodium.aead.gcm.decode(input: string, key: string): string

sodium.aead.gcm.decode(input: string, key: string): string
  • Decrypts a message based on the key, this handles its own nonce internally.
  • The nonce is applied to the start of the message.

AEGIS-256

A new authenticated encryption algorithm that is designed to be fast and secure, using a 256-bit key.
For applications these might not be standardized yet.

sodium.aead.aegis.nonce(): string

sodium.aead.aegis.nonce(): string
  • Generates a nonce which is used in securing uniqueness.

sodium.aead.aegis.key(base?: string, salt?: string): string

sodium.aead.aegis.key(base?: string, salt?: string): string
  • Generates a key, providing a base acts as an offset, with providing a salt for greater resiliance.

sodium.aead.aegis.encrypt(input: string, key: string, nonce: string): string

sodium.aead.aegis.encrypt(input: string, key: string, nonce: string): string
  • Encrypts a messages based on the key and added nonce.

sodium.aead.aegis.decrypt(input: string, key: string, nonce: string): string

sodium.aead.aegis.decrypt(input: string, key: string, nonce: string): string
  • Decrypts a messages based on the key and added nonce.

sodium.aead.aegis.encode(input: string, key: string): string

sodium.aead.aegis.encode(input: string, key: string): string
  • Encrypts a message based on the key, this generates its own nonce internally.
  • The nonce is applied to the start of the message.

sodium.aead.aegis.decode(input: string, key: string): string

sodium.aead.aegis.decode(input: string, key: string): string
  • Decrypts a message based on the key, this handles its own nonce internally.
  • The nonce is applied to the start of the message.