1.0.2 • Published 3 years ago

as-hmac-sha2 v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

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);
1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago