enigma-hash
Advanced tools
Comparing version 1.2.1 to 1.3.0
37
cli.js
@@ -1,32 +0,29 @@ | ||
const colors = require("colors") | ||
const crypto = require("crypto") | ||
const colors = require("colors"); | ||
const crypto = require("crypto"); | ||
function run() { | ||
const arguments = process.argv | ||
const opts = arguments.slice(2, arguments.length) | ||
const arguments = process.argv; | ||
const opts = arguments.slice(2, arguments.length); | ||
try { | ||
const inputVal = opts.slice(opts.indexOf("--input") + 1, opts.indexOf("--input") + 2)[0] | ||
const algorithmVal = opts.slice( | ||
opts.indexOf("--algorithm") + 1, | ||
opts.indexOf("--algorithm") + 2 | ||
)[0] | ||
const encodingVal = opts.slice(opts.indexOf("--code") + 1, opts.indexOf("--code") + 2)[0] | ||
const inputVal = opts.slice(opts.indexOf("--data") + 1, opts.indexOf("--data") + 2)[0]; | ||
const algorithmVal = opts.slice(opts.indexOf("--alg") + 1, opts.indexOf("--alg") + 2)[0]; | ||
const encodingVal = opts.slice(opts.indexOf("--code") + 1, opts.indexOf("--code") + 2)[0]; | ||
if (algorithmVal === "sha256") { | ||
const h = crypto.createHash(algorithmVal.toLowerCase() || "sha256") | ||
h.update(inputVal) | ||
const res = h.digest(encodingVal || "hex") | ||
console.log(colors.green(res)) | ||
const h = crypto.createHash(algorithmVal.toLowerCase() || "sha256"); | ||
h.update(inputVal); | ||
const res = h.digest(encodingVal || "hex"); | ||
console.log(colors.green(res)); | ||
} else { | ||
const h = crypto.createHash(algorithmVal.toLowerCase() || "sha512") | ||
h.update(inputVal) | ||
const res = h.digest(encodingVal || "hex") | ||
console.log(colors.green(res)) | ||
const h = crypto.createHash(algorithmVal.toLowerCase() || "sha512"); | ||
h.update(inputVal); | ||
const res = h.digest(encodingVal || "hex"); | ||
console.log(colors.green(res)); | ||
} | ||
} catch (error) { | ||
console.log(colors.red.bold("Error occured, please type all required fields")) | ||
console.log(colors.red.bold("Error occured, please type all required fields")); | ||
} | ||
} | ||
run() | ||
run(); |
16
index.js
@@ -1,15 +0,15 @@ | ||
const crypto = require("crypto") | ||
const crypto = require("crypto"); | ||
function hash(input = "", type = "", code = "", key) { | ||
const algorithms = ["sha256", "sha512"] | ||
const encoding = ["hex", "latin1", "base64"] | ||
const algorithms = ["sha256", "sha512"]; | ||
const encoding = ["hex", "latin1", "base64"]; | ||
if (algorithms.includes(type)) { | ||
const h = key ? crypto.createHmac(type, key) : crypto.createHash(type) | ||
h.update(input) | ||
const h = key ? crypto.createHmac(type, key) : crypto.createHash(type); | ||
h.update(input); | ||
return h.digest(encoding[encoding.indexOf(code)] || "hex") | ||
return h.digest(encoding[encoding.indexOf(code)] || "hex"); | ||
} | ||
return type ? "Algorithm not supported" : "Algorithm not provided" | ||
return type ? "Algorithm not supported" : "Algorithm not provided"; | ||
} | ||
@@ -19,2 +19,2 @@ | ||
hash | ||
} | ||
}; |
@@ -1,2 +0,2 @@ | ||
const { hash } = require("./index") | ||
const { hash } = require("./index"); | ||
@@ -7,4 +7,4 @@ // sha256 test | ||
"a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e" | ||
) | ||
}) | ||
); | ||
}); | ||
@@ -16,4 +16,4 @@ // sha512 test | ||
"2c74fd17edafd80e8447b0d46741ee243b7eb74dd2149a0ab1b9246fb30382f27e853d8585719e0e67cbda0daa8f51671064615d645ae27acb15bfb1447f459b" | ||
) | ||
}) | ||
); | ||
}); | ||
@@ -24,4 +24,4 @@ // hmac sha256 test | ||
"a722630ff96e1aece313dc76a6af89673884bbdb45adec31678f11e44e0578b7" | ||
) | ||
}) | ||
); | ||
}); | ||
@@ -32,3 +32,3 @@ // hmac sha512 test | ||
"8432d61b16b75978b3b8da48a10f44ea72aba3f66f283bdc696dccdff50a897bc946270501e9e4ee122d066b9aef2e60a8789aaf8d636b6a44521ba64371e109" | ||
) | ||
}) | ||
); | ||
}); |
{ | ||
"name": "enigma-hash", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "Demystifying the hashing of data", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"test": "jest test", | ||
"format": "prettier --no-semi --tab-width 2 --print-width 100 --write **/*.js", | ||
"format": "prettier --tab-width 2 --print-width 100 --write **/*.js", | ||
"postversion": "git push && git push --tags" | ||
@@ -37,3 +37,3 @@ }, | ||
"jest": "23.6.0", | ||
"prettier": "1.15.3" | ||
"prettier": "^1.18.2" | ||
}, | ||
@@ -40,0 +40,0 @@ "publishConfig": { |
@@ -112,3 +112,3 @@ <div align="center"> | ||
```sh | ||
enigma --algorithm sha256 --code hex --input <some string to hash> | ||
enigma --alg sha256 --code hex --data <some string to hash> | ||
``` | ||
@@ -115,0 +115,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2634957
64