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.
61 lines
1.3 KiB
61 lines
1.3 KiB
// crypto.js
|
|
// Copyright (C) 2024 DTP Technologies, LLC
|
|
// All Rights Reserved
|
|
|
|
'use strict';
|
|
|
|
import crypto from 'node:crypto';
|
|
|
|
import { SiteService } from '../../lib/site-lib.js';
|
|
|
|
export default class CryptoService extends SiteService {
|
|
|
|
static get slug () { return 'crypto'; }
|
|
static get name ( ) { return 'CryptoService'; }
|
|
|
|
constructor (dtp) {
|
|
super(dtp, CryptoService);
|
|
}
|
|
|
|
maskPassword (passwordSalt, password) {
|
|
const hash = crypto.createHash('sha256');
|
|
|
|
hash.update(process.env.DTP_PASSWORD_SALT);
|
|
hash.update(passwordSalt);
|
|
hash.update(password);
|
|
|
|
return hash.digest('hex');
|
|
}
|
|
|
|
createHash (content, algorithm = 'sha256') {
|
|
const hash = crypto.createHash(algorithm);
|
|
hash.update(content);
|
|
return hash.digest('hex');
|
|
}
|
|
|
|
hash32 (text) {
|
|
var hash = 0, i, chr;
|
|
if (text.length === 0) {
|
|
return hash;
|
|
}
|
|
for (i = text.length - 1; i >= 0; --i) {
|
|
chr = text.charCodeAt(i);
|
|
// jshint ignore:start
|
|
hash = ((hash << 5) - hash) + chr;
|
|
hash |= 0;
|
|
// jshint ignore:end
|
|
}
|
|
hash = hash.toString(16);
|
|
if (hash[0] === '-') {
|
|
hash = hash.slice(1);
|
|
}
|
|
return hash;
|
|
}
|
|
|
|
createProof (secret, challenge) {
|
|
let hash = crypto.createHash('sha256');
|
|
hash.update(secret);
|
|
hash.update(challenge);
|
|
return hash.digest('hex');
|
|
}
|
|
}
|