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: 2 days ago
JSON representation
SHA-256, SHA-512, HMAC-SHA-256, HMAC-SHA-512 for AssemblyScript.
- Host: GitHub
- URL: https://github.com/jedisct1/as-hmac-sha2
- Owner: jedisct1
- Created: 2021-05-13T14:19:19.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-23T11:03:39.000Z (over 2 years ago)
- Last Synced: 2025-03-29T10:33:31.605Z (24 days ago)
- Topics: assemblyscript, hmac, sha256, sha512
- Language: TypeScript
- Homepage:
- Size: 14.6 KB
- Stars: 15
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
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);
```