Yield generated for b69d33a7-27e5-483b-b6eb-b5673eee5896
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
633 B

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