velt/crypto
API referenceSHA-256 and SHA-1, HMAC, secure randomness and constant-time comparison: what a program needs to sign and check tokens and webhooks, store content by hash, or make session ids. For a walkthrough, read the guide.
Exports
a and b are equal, in time that depends only on their lengths (not on where they differ), for comparing MACs and tokens.hmacSha1HMAC-SHA1 (RFC 2104 / RFC 2202) of data under key.hmacSha256HMAC-SHA256 (RFC 2104 / RFC 4231) of data under key.randomBytesn cryptographically secure random bytes (OS generator).randomIntA uniformly distributed secure random integer in [min, max) (Node's crypto.randomInt); rejection sampling avoids modulo bias.sha1SHA-1 digest (20 bytes) of data.sha1HexLowercase hex SHA-1 of the UTF-8 bytes of s.sha256SHA-256 digest (32 bytes) of data.sha256HexLowercase hex SHA-256 of the UTF-8 bytes of s.CryptoErrorThrown by randomInt for an empty or too large range, or a bound that is not a safe integer.Re-exported from velt/crypto/compare
function timingSafeEqual(a: u8[], b: u8[]): boolWhether a and b are equal, in time that depends only on their lengths (not on where they
differ), for comparing MACs and tokens. Different lengths return false at once.
Re-exported from velt/crypto/hmac
function hmacSha1(key: u8[], data: u8[]): u8[]HMAC-SHA1 (RFC 2104 / RFC 2202) of data under key.
Re-exported from velt/crypto/hmac
function hmacSha256(key: u8[], data: u8[]): u8[]HMAC-SHA256 (RFC 2104 / RFC 4231) of data under key.
Re-exported from velt/crypto/random
function randomBytes(n: usize): u8[]n cryptographically secure random bytes (OS generator).
Re-exported from velt/crypto/random
function randomInt(min: i64, max: i64): i64A uniformly distributed secure random integer in [min, max) (Node's crypto.randomInt);
rejection sampling avoids modulo bias. Throws CryptoError, with Node's messages, when min
or max is not a safe integer, max <= min, or max - min is 2^48 or more.
Re-exported from velt/crypto/sha1
function sha1(data: u8[]): u8[]SHA-1 digest (20 bytes) of data. Not collision resistant; see the module comment.
Re-exported from velt/crypto/sha1
function sha1Hex(s: string): stringLowercase hex SHA-1 of the UTF-8 bytes of s.
Re-exported from velt/crypto/sha256
function sha256(data: u8[]): u8[]SHA-256 digest (32 bytes) of data.
Re-exported from velt/crypto/sha256
function sha256Hex(s: string): stringLowercase hex SHA-256 of the UTF-8 bytes of s.
Re-exported from velt/crypto/errors
class CryptoError extends ErrorThrown by randomInt for an empty or too large range, or a bound that is not a safe integer.
constructor(message: string)No doc comment yet