Module rspamd_cryptobox

Rspamd cryptobox is a module that operates with digital signatures and hashes.

Example:

local hash = require "rspamd_cryptobox_hash"

local h = hash.create()
h:update('hello world')
print(h:hex())

Brief content:

Functions:

rspamd_cryptobox_pubkey.load(file[, type[, alg]])

rspamd_cryptobox_pubkey.create(data[, type[, alg]])

rspamd_cryptobox_keypair.load(file)

rspamd_cryptobox_keypair.create(ucl_data)

rspamd_cryptobox_signature.load(file)

rspamd_cryptobox_signature.create(data)

rspamd_cryptobox_hash.create([string])

rspamd_cryptobox_hash.create_specific(type, [string])

rspamd_cryptobox_hash.create_keyed(key, [string])

rspamd_cryptobox.verify_memory(pk, sig, data)

rspamd_cryptobox.verify_file(pk, sig, file)

rspamd_cryptobox.sign_memory(kp, data)

rspamd_cryptobox.sign_file(kp, file)

Methods:

rspamd_cryptobox_signature:save(file)

cryptobox_signature:hex()

cryptobox_signature:base32()

cryptobox_signature:base64()

cryptobox_signature:bin()

cryptobox_hash:update(data)

cryptobox_hash:reset()

cryptobox_hash:hex()

cryptobox_hash:base32()

cryptobox_hash:base64()

cryptobox_hash:bin()

Functions

The module rspamd_cryptobox defines the following functions.

Function rspamd_cryptobox_pubkey.load(file[, type[, alg]])

Loads public key from base32 encoded file

Parameters:

  • file {string}: filename to load
  • type {string}: optional ‘sign’ or ‘kex’ for signing and encryption
  • alg {string}: optional ‘default’ or ‘nist’ for curve25519/nistp256 keys

Returns:

  • {cryptobox_pubkey}: new public key

Back to module description.

Function rspamd_cryptobox_pubkey.create(data[, type[, alg]])

Loads public key from base32 encoded file

Parameters:

  • base32 {base32 string}: string with the key
  • type {string}: optional ‘sign’ or ‘kex’ for signing and encryption
  • alg {string}: optional ‘default’ or ‘nist’ for curve25519/nistp256 keys

Returns:

  • {cryptobox_pubkey}: new public key

Back to module description.

Function rspamd_cryptobox_keypair.load(file)

Loads public key from UCL file

Parameters:

  • file {string}: filename to load

Returns:

  • {cryptobox_keypair}: new keypair

Back to module description.

Function rspamd_cryptobox_keypair.create(ucl_data)

Loads public key from UCL data

Parameters:

  • ucl_data {string}: ucl to load

Returns:

  • {cryptobox_keypair}: new keypair

Back to module description.

Function rspamd_cryptobox_signature.load(file)

Loads signature from raw file

Parameters:

  • file {string}: filename to load

Returns:

  • {cryptobox_signature}: new signature

Back to module description.

Function rspamd_cryptobox_signature.create(data)

Creates signature object from raw data

Parameters:

  • raw {data}: signature data

Returns:

  • {cryptobox_signature}: signature object

Back to module description.

Function rspamd_cryptobox_hash.create([string])

Creates new hash context

Parameters:

  • data {string}: optional string to hash

Returns:

  • {cryptobox_hash}: hash object

Back to module description.

Function rspamd_cryptobox_hash.create_specific(type, [string])

Creates new hash context

Parameters:

  • type {string}: type of signature
  • data {string}: raw signature data

Returns:

  • {cryptobox_hash}: hash object

Back to module description.

Function rspamd_cryptobox_hash.create_keyed(key, [string])

Creates new hash context with specified key

Parameters:

  • key {string}: key

Returns:

  • {cryptobox_hash}: hash object

Back to module description.

Function rspamd_cryptobox.verify_memory(pk, sig, data)

Check memory using specified cryptobox key and signature

Parameters:

  • pk {pubkey}: public key to verify
  • signature {sig}: to check
  • data {string}: data to check signature against

Returns:

  • {boolean}: true - if string matches cryptobox signature

Back to module description.

Function rspamd_cryptobox.verify_file(pk, sig, file)

Check file using specified cryptobox key and signature

Parameters:

  • pk {pubkey}: public key to verify
  • signature {sig}: to check
  • file {string}: to load data from

Returns:

  • {boolean}: true - if string matches cryptobox signature

Back to module description.

Function rspamd_cryptobox.sign_memory(kp, data)

Sign data using specified keypair

Parameters:

  • kp {keypair}: keypair to sign
  • data {string}:

Returns:

  • {cryptobox_signature}: signature object

Back to module description.

Function rspamd_cryptobox.sign_file(kp, file)

Sign file using specified keypair

Parameters:

  • kp {keypair}: keypair to sign
  • filename {string}:

Returns:

  • {cryptobox_signature}: signature object

Back to module description.

Methods

The module rspamd_cryptobox defines the following methods.

Method rspamd_cryptobox_signature:save(file)

Stores signature in raw file

Parameters:

  • file {string}: filename to use

Returns:

  • {boolean}: true if signature has been saved

Back to module description.

Method cryptobox_signature:hex()

Return hex encoded signature string

Parameters:

No parameters

Returns:

  • {string}: raw value of signature

Back to module description.

Method cryptobox_signature:base32()

Return base32 encoded signature string

Parameters:

No parameters

Returns:

  • {string}: raw value of signature

Back to module description.

Method cryptobox_signature:base64()

Return base64 encoded signature string

Parameters:

No parameters

Returns:

  • {string}: raw value of signature

Back to module description.

Method cryptobox_signature:bin()

Return raw signature string

Parameters:

No parameters

Returns:

  • {string}: raw value of signature

Back to module description.

Method cryptobox_hash:update(data)

Updates hash with the specified data (hash should not be finalized using hex or bin methods)

Parameters:

  • data {string}: data to hash

Returns:

No return

Back to module description.

Method cryptobox_hash:reset()

Resets hash to the initial state

Parameters:

No parameters

Returns:

No return

Back to module description.

Method cryptobox_hash:hex()

Finalizes hash and return it as hex string

Parameters:

No parameters

Returns:

  • {string}: hex value of hash

Back to module description.

Method cryptobox_hash:base32()

Finalizes hash and return it as zbase32 string

Parameters:

No parameters

Returns:

  • {string}: base32 value of hash

Back to module description.

Method cryptobox_hash:base64()

Finalizes hash and return it as base64 string

Parameters:

No parameters

Returns:

  • {string}: base64 value of hash

Back to module description.

Method cryptobox_hash:bin()

Finalizes hash and return it as raw string

Parameters:

No parameters

Returns:

  • {string}: raw value of hash

Back to module description.

Back to top.