Home  Contents

pki:sign()

Cipher/PKI Core4 Lua Commands

SYNOPSIS

  1. sig = pki:sign(data, dummy[, hash])
  2. success = pki:verify(data, sig, dummy[, hash])

DESCRIPTION

Cryptographically sign some data with pki:sign() or check a signature with pki:verify().

The object must have a key loaded before these functions can be called.

The data to be signed/verified is passed as a string in data.

The value sig holds the signature.

The parameter dummy is not used.

The optional parameter hash selects the one-way hash function. The default is SHA256. Supported hashes are: raw, MD2, MD4, MD5, SHA1, SHA224, SHA256, SHA384, SHA512, RIPEMD160.

Unless the hash parameter is "raw" (no hash), the implementation first calculates the specified one-way hash function of the passed data. Then, the signature creation or verification is calculated over the hash value.

Signing is done by calling the mbedTLS function mbedtls_pk_sign() . Verification is handled by mbedtls_pk_verify() .

RETURN VALUE

On success, the signing function returns a signature that can be passed back to the verification function. The verification function returns true on success.

In case of an error both functions return three values: nil, a string describing the error and a negative error code from the underlying mbed TLS implementation.