as-hmac-sha2

1.0.2 • Public • Published

HMAC-SHA-256 and HMAC-SHA-512 for AssemblyScript

Self-contained implementations of SHA-256, SHA-512, HMAC-SHA-256 and HMAC-SHA-512 for AssemblyScript.

Simple hashing:

let msg = Uint8Array.wrap(String.UTF8.encode("test"));
let h = Sha256.hash(msg);

Chunked input:

let st = new Sha256();
st.update(msg1);
st.update(msg2);
let h = st.final();

HMAC:

let msg = Uint8Array.wrap(String.UTF8.encode("message"));
let key = Uint8Array.wrap(String.UTF8.encode("key"));
let mac = Sha256.hmac(msg, key);

Constant-time check for equality:

let ok = verify(mac, expected_mac);

Constant-time hexadecimal encoding/decoding:

let hex = bin2hex(h);
let bin = hex2bin(hex);

Dependencies (0)

    Dev Dependencies (2)

    Package Sidebar

    Install

    npm i as-hmac-sha2

    Weekly Downloads

    4

    Version

    1.0.2

    License

    ISC

    Unpacked Size

    773 kB

    Total Files

    14

    Last publish

    Collaborators

    • jedisct1