Capy-Bearer Documentation

crypto_equal

host call

Capy

function crypto_equal(left : string, right : string) bool

Description

crypto_equal() compares byte strings in constant time.

Use it to compare secrets such as HMACs and tokens. Do not use == to compare secrets.

Parameters

left : the expected byte string

right : the submitted byte string

Return Values

true if both byte strings are equal.

Example

Capy

var expected := hmac_sha256("key", "payload")
if crypto_equal(expected, hmac_sha256("key", "payload")) { print("valid\n") } else { print("invalid\n") }