hello git
This commit is contained in:
commit
3c308ccb21
4 changed files with 279 additions and 0 deletions
62
hash.ts
Normal file
62
hash.ts
Normal file
|
@ -0,0 +1,62 @@
|
|||
import IGA from './IGA';
|
||||
import fs from 'fs';
|
||||
|
||||
const args = process.argv.slice(2)
|
||||
const version = "1.1"
|
||||
|
||||
function printHelp() {
|
||||
console.log("IGA commandline tool v" + version)
|
||||
console.log("Usage: tsx hash.ts <hash|verify> <input file> [<hash to verify>] [options]");
|
||||
console.log("Options:");
|
||||
console.log("[<salt = 0>] [<iterations = 32>] [<length of the hash = 32>]");
|
||||
}
|
||||
|
||||
if (args[0] == "hash") {
|
||||
if (args.length < 2) {
|
||||
console.log("Not enough arguments");
|
||||
printHelp()
|
||||
process.exit(0)
|
||||
}
|
||||
if (!fs.existsSync(args[1])) {
|
||||
console.log("File not found: " + args[1])
|
||||
process.exit(0)
|
||||
}
|
||||
let fileData = fs.readFileSync(args[1], 'utf8');
|
||||
let salt = args[2] ? parseInt(args[2]) : 0
|
||||
let iterations = args[3] ? parseInt(args[3]) : 32
|
||||
let len = args[4] ? parseInt(args[4]) : 32
|
||||
try {
|
||||
let hash = IGA.hash(fileData, salt, iterations, len)
|
||||
console.log(hash)
|
||||
} catch (e) {
|
||||
console.error("Error while creating hash: " + e.stack)
|
||||
}
|
||||
} else if (args[0] == "verify") {
|
||||
if (args.length < 3) {
|
||||
console.log("Not enough arguments");
|
||||
printHelp()
|
||||
process.exit(0)
|
||||
}
|
||||
if (!fs.existsSync(args[1])) {
|
||||
console.log("File not found: " + args[1])
|
||||
process.exit(0)
|
||||
}
|
||||
let fileData = fs.readFileSync(args[1], 'utf8');
|
||||
let hashToVerify = args[2]
|
||||
let salt = args[3] ? parseInt(args[3]) : 0
|
||||
let iterations = args[4] ? parseInt(args[4]) : 32
|
||||
let len = args[5] ? parseInt(args[5]) : 32
|
||||
try {
|
||||
let verify = IGA.verifyHash(fileData, hashToVerify, salt, iterations, len)
|
||||
if (verify.valid) {
|
||||
console.log("Hash is valid!")
|
||||
} else {
|
||||
console.log("Hash is invalid!")
|
||||
console.log("Reason: " + verify.reason)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Error while verifying hash: " + e.stack)
|
||||
}
|
||||
} else {
|
||||
printHelp()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue