Skip to content

Commit 103d9d4

Browse files
author
Felix Robles
committed
add sha1hmac
1 parent df0c91b commit 103d9d4

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

package-lock.json

Lines changed: 4 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cryptography/abstract/HMAC.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Digest } from "./Digest";
2+
/**
3+
* A HMAC ( commonly referred to as a Hash ) (hash-based message authentication
4+
* code) is a type of message authentication code (MAC) that uses a
5+
* cryptographic hash function and a secret key. It may be used to verify data
6+
* integrity and authentication of a message.
7+
*
8+
* Strontium assumes that HMAC functions will run on input that is entirely
9+
* in memory. The interface does not currently support calculations against a
10+
* stream.
11+
*
12+
* The exact nature or security properties of a given HMAC implementation
13+
* will vary based on the implementing class.
14+
*/
15+
export abstract class HMAC extends Digest {
16+
/**
17+
* Create a new HMAC Encrypter.
18+
*
19+
* @param secretKey - The shared secret to use for encryption.
20+
*/
21+
constructor(protected secretKey: Buffer) {
22+
super()
23+
}
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { HMAC } from "../../abstract/HMAC"
2+
import { createHmac } from "crypto"
3+
4+
/**
5+
* The SHA1HMAC provides a HMAC implementation using SHA1 based on Node's
6+
* OpenSSL.
7+
*
8+
* This implementation relies on the node crypto implementation and may vary based
9+
* on the build flags of the underlying runtime.
10+
*/
11+
export class SHA1HMAC extends HMAC {
12+
public async calculate(input: Buffer): Promise<Buffer> {
13+
let hmacBuilder = createHmac("sha1", this.secretKey)
14+
hmacBuilder.update(input)
15+
16+
return hmacBuilder.digest()
17+
}
18+
}

0 commit comments

Comments
 (0)