mirror of
https://github.com/certd/certd.git
synced 2026-04-16 14:00:51 +08:00
24 lines
673 B
TypeScript
24 lines
673 B
TypeScript
import CryptoJS from 'crypto-js';
|
|
|
|
export class CryptoUtils {
|
|
private constructor() {}
|
|
|
|
/**
|
|
* hmac+sha256+hex
|
|
*/
|
|
public static sha256Hex(s: string): string {
|
|
const hash = CryptoJS.SHA256(s);
|
|
return hash.toString(CryptoJS.enc.Hex).toLowerCase();
|
|
}
|
|
|
|
/**
|
|
* hmac+sha256
|
|
*/
|
|
public static hmac256(secretKey: string, message: string): string {
|
|
const keyWordArray = CryptoJS.enc.Utf8.parse(secretKey);
|
|
const messageWordArray = CryptoJS.enc.Utf8.parse(message);
|
|
const hash = CryptoJS.HmacSHA256(messageWordArray, keyWordArray);
|
|
return hash.toString(CryptoJS.enc.Hex).toLowerCase();
|
|
}
|
|
}
|