Skip to main content
Version: 9.2605.x.x RR

Verifier

Class function

nevis.crypto.verifier.new(key)

Instantiates a new verifier object for signing and verifying strings with HMAC-SHA256.

  • key: The signing key, interpreted as an ASCII string (1 byte per character). Use \x01\xFF for non-ASCII values; the key must not contain \x00.

Sample:

local verifier = nevis.crypto.verifier.new("TheKey")

Object methods

Each parameter is interpreted as an ASCII string (1 byte per character), but is not limited to ASCII characters. For non-ASCII values, use \x01\xFF. Parameters must not contain \x00 — if they do, the verifier ignores that character and everything that follows. Because of this, binary inputs should be Base64 encoded first.

verifier:sign(data)

Returns the given data followed by its HMAC-SHA256 hash, separated by an underscore.

Sample:

local signedValue = verifier:sign("TheTextToSign")

verifier:verify(signedValue)

Expects a value signed with verifier:sign(). Returns the original data (without the signature) if the signature matches, or nil if it does not.

Sample:

local verifiedData = verifier:verify(signedValue)

verifier:createTag(data)

Returns the HMAC-SHA256 signature (tag) for the given data. The tag can be verified with verifier:verifyTag().

Sample:

local tag = verifier:createTag("TheText")

verifier:verifyTag(data, tag)

Returns true if the data matches the given tag, or false if it does not.

Sample:

local result = verifier:verifyTag("TheText", tag)

Example

local verifier = nevis.crypto.verifier.new("TheKey")
local signedMsg = verifier:sign("TheTextToSign") -- signedMsg is TheTextToSign_signatureTag
local verifiedValue = verifier:verify(signedMsg)
if verifiedValue then
-- verifiedValue is "TheTextToSign"
else
-- verifying failed
end
local tagText = verifier:createTag("TheTextToTag") -- tagText is HrRoBMhhxjCaJMOnGfMoeaUSGOruiWiwGdwKQtsUOfALKF
local tVerifiedValue = verifier:verifyTag("TheTextToTag", tagText)
if tVerifiedValue then
-- tVerifiedValue is "TheTextToTag"
else
-- verifying failed
end