rewrite to a module

This commit is contained in:
Mystikfluu
2022-08-19 19:29:14 +02:00
parent c78f4cba3a
commit 6ed17497c5
13 changed files with 1522 additions and 540 deletions
+18 -17
View File
@@ -1,5 +1,4 @@
const crypto = require('crypto');
import crypto from "crypto";
/**
* hashes with the secure hashing algorithm 256
* @param {string} str string to hash
@@ -7,19 +6,21 @@ const crypto = require('crypto');
* @param {number} num amount of times to hash, defaults to 1
* @returns {string} base64 digested hash
*/
function SHA256(str,salt,num) {
if(!num && num!==0)num=1;
if(!str)return;
let ret = str;
for (let i = 0; i < num; i++) {
ret = crypto
.createHash("sha256")
.update(ret+salt)
.digest("base64");
}
return ret;
}
module.exports = {
SHA256: SHA256
function SHA256(str, salt, num) {
if (!num && num !== 0)
num = 1;
if (!str)
return;
let ret = str;
for (let i = 0; i < num; i++) {
ret = crypto
.createHash("sha256")
.update(ret + salt)
.digest("base64");
}
return ret;
}
export { SHA256 };
export default {
SHA256: SHA256
};