💾 Archived View for iich.space › src › util › hash.ts captured on 2021-12-03 at 14:04:38.

View Raw

More Information

-=-=-=-=-=-=-

import { Encoding, createHash } from 'crypto';

export const generateHash = (
  input: string,
  encoding: Encoding = 'utf8',
): string => {
  const hash = createHash('sha256');

  hash.update(process.env.SALT!);
  hash.update(input, encoding);

  return hash
    .digest()
    .toString('base64')
    .slice(0)
    .replaceAll('+', '-')
    .replaceAll('/', '_');
};