Yield generated for d159283b-474f-41f2-8cf3-cf7f42d363d7
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

28 lines
639 B

import { Injectable } from '@nestjs/common';
import { argon2id, hash, verify } from 'argon2';
@Injectable()
export class CryptoService {
private readonly type = argon2id;
constructor() {}
/**
* Compare hash
* @param {string} plain
* @param {string} hash
* @returns {Promise<boolean>}
*/
public async compare(plain: string, hashString: string): Promise<boolean> {
return await verify(hashString, plain);
}
/**
* Generate hash
* @param {string} plain
* @returns {Promise<string>}
*/
public async hash(plain: string): Promise<string> {
return await hash(plain, { type: this.type });
}
}