This commit is contained in:
Tutur33
2023-11-24 22:35:41 +01:00
parent 3c0b507a93
commit 7644b2a0f7
45165 changed files with 4803356 additions and 3 deletions
+17
View File
@@ -0,0 +1,17 @@
/// <reference types="node" />
/**
* A generic class for generating SHA-256 Hmac for verifying the value
* integrity.
*/
export declare class Hmac {
private key;
constructor(key: Buffer);
/**
* Generate the hmac
*/
generate(value: string): string;
/**
* Compare raw value against an existing hmac
*/
compare(value: string, existingHmac: string): boolean;
}
+35
View File
@@ -0,0 +1,35 @@
"use strict";
/*
* @adonisjs/encryption
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Hmac = void 0;
const crypto_1 = require("crypto");
const helpers_1 = require("@poppinss/utils/build/helpers");
/**
* A generic class for generating SHA-256 Hmac for verifying the value
* integrity.
*/
class Hmac {
constructor(key) {
this.key = key;
}
/**
* Generate the hmac
*/
generate(value) {
return helpers_1.base64.urlEncode((0, crypto_1.createHmac)('sha256', this.key).update(value).digest());
}
/**
* Compare raw value against an existing hmac
*/
compare(value, existingHmac) {
return (0, helpers_1.safeEqual)(this.generate(value), existingHmac);
}
}
exports.Hmac = Hmac;