Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jedisct1/as-hmac-sha2

SHA-256, SHA-512, HMAC-SHA-256, HMAC-SHA-512 for AssemblyScript.
https://github.com/jedisct1/as-hmac-sha2

assemblyscript hmac sha256 sha512

Last synced: 4 months ago
JSON representation

SHA-256, SHA-512, HMAC-SHA-256, HMAC-SHA-512 for AssemblyScript.

Awesome Lists containing this project

README

        

# 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:

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

Chunked input:

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

HMAC:

```typescript
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:

```typescript
let ok = verify(mac, expected_mac);
```

Constant-time hexadecimal encoding/decoding:

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