Comparing version 1.0.0 to 1.0.1
169
app.js
@@ -5,18 +5,8 @@ const fs = require("fs"); | ||
const util = require('util'); | ||
const setTimeoutPromise = util.promisify(setTimeout); | ||
const colors = require("./colors.js"); | ||
const cipherMethod = require("./cipherMethod.js"); | ||
function is(type, obj) { | ||
var clas = Object.prototype.toString.call(obj).slice(8, -1); | ||
return obj !== undefined && obj !== null && clas === type; | ||
} | ||
//global variables | ||
const delay = "40000" ; | ||
const filePath = "/Apocalypto.2006.720p.BluRay.x264-[YTS.ME].mp4"; | ||
const rawDataPath = `RawData-${filePath.replace("/","")}`; | ||
const cipheredFilePath = "/ciphered-" + filePath.replace("/","") + ".txt"; | ||
const decipheredFilePath = "/deciphered-" + filePath.replace("/",""); | ||
let _key = "cacnga153"; | ||
@@ -26,2 +16,6 @@ let _sourceFile = ""; | ||
//Encipher the file | ||
//Param: String "fullFilePath", String "password_key" | ||
function cipher( file, key ){ | ||
@@ -32,24 +26,29 @@ | ||
let cipheredData = ""; | ||
let rawData = ""; | ||
console.log(" "); | ||
console.log("CIPHERING initiated............"); | ||
log(" "); | ||
log("CIPHERING initiated............"); | ||
let cipher = crypto.createDecipher("aes-256-ctr", key); | ||
log(`Cipher Method: ${cipherMethod}`); | ||
let cipher = crypto.createCipher(cipherMethod, key); | ||
let streames = createStreames(file, _destinationFile); | ||
console.log(`Ciphering/Encryption streames => ${streames}`); | ||
log(`Ciphering/Encryption streames => ${streames}`); | ||
streames.input.pipe(cipher).pipe(streames.output); | ||
console.log(".............CIPHERING will be done in a SHORT WHILE PLEASE WAIT..........."); | ||
log(".............CIPHERING will be done in a SHORT WHILE PLEASE WAIT..........."); | ||
} | ||
//CREATE READ AND WRITE STREAMS | ||
//FOR THE INPUT AND OUTPUT SREAM RESPECTIVELY | ||
//Param: String, String | ||
function createStreames(inputReadStreamFilePath, outputWriteStreamFilePath){ | ||
//CREATE READ AND WRITE STREAMS | ||
//FOR THE INPUT AND OUTPUT SREAM RESPECTIVELY | ||
if(inputReadStreamFilePath && outputWriteStreamFilePath){ | ||
@@ -64,3 +63,3 @@ | ||
return console.error("Error: Parameters(files) missing ," | ||
return logErr("Error: Parameters(files) missing ," | ||
+ "cannot create input and output files for deciphering )"); | ||
@@ -70,5 +69,7 @@ | ||
} | ||
} | ||
//Decipher the file | ||
//Param: String "fullFilePath", String "password_key" | ||
@@ -82,60 +83,114 @@ function decipher(file, key){ | ||
console.log(" "); | ||
console.log("DECIPHERING initiated..........."); | ||
log(" "); | ||
log("DECIPHERING initiated..........."); | ||
let decipher = crypto.createDecipher("aes-256-ctr", key); | ||
let decipher = crypto.createDecipher(cipherMethod, key); | ||
let streames = createStreames(file, _destinationFile); | ||
console.log(`Deciphering/Decryption Streames => ${streames}`); | ||
log(`Deciphering/Decryption Streames => ${streames}`); | ||
streames.input.pipe(decipher).pipe(streames.output); | ||
console.log(".............DECIPHERING will be done in a SHORT WHILE PLEASE WAIT..........."); | ||
log(".............DECIPHERING will be done in a SHORT WHILE PLEASE WAIT..........."); | ||
}; | ||
function recreate(file){ | ||
console.prompt() | ||
//js efficient Object type checking | ||
//Param: String, Object | ||
var image = fs.readFile(file, function(err, data) { | ||
fs.writeFile('output' + file.replace("/", ""), data, 'binary', function (err) { | ||
if (err) { | ||
console.log("There was an error writing the image"); | ||
} | ||
else { | ||
console.log("There file was written"); | ||
} | ||
}); | ||
}); | ||
function is(type, obj) { | ||
var clas = Object.prototype.toString.call(obj).slice(8, -1); | ||
return obj !== undefined && obj !== null && clas === type; | ||
} | ||
//add empty row in console | ||
function space(){ | ||
console.log(` `); | ||
} | ||
//log out messages to the console | ||
//Param: String | ||
function log(msg){ | ||
space(); | ||
console.log(colors.fgCyan(), msg, colors.reset()); | ||
space(); | ||
} | ||
//logout errors to the console | ||
//Param: String | ||
function logErr(err){ | ||
space(); | ||
console.error(colors.fgMagenta(), err, colors.reset()); | ||
space(); | ||
} | ||
//parse urls with double quotation marks around them | ||
//Param: String | ||
function parseUrl(urlString){ | ||
if(urlString[0] === '"'){ | ||
urlString = urlString.replace('"', ""); | ||
} | ||
if(urlString[urlString.length-1] === '"'){ | ||
urlString = urlString.replace('"', ""); | ||
} | ||
log(`final parsed url => ${urlString}`); | ||
return urlString; | ||
} | ||
//user action configuration console wizard | ||
//Para: action === String "Encrypt" / "Decrypt" | ||
function config(action){ | ||
stdio.question(`What file do you want to ${action}? (PLEASE INCUDE FILE EXTENSION EG. /file.txt)`, (err, sourceFile) => { | ||
stdio.question(`What file do you want to ${action}? (PLEASE INCUDE FILE EXTENSION EG. FullFilePath.txt)`, (err, sourceFile) => { | ||
action ? _sourceFile = sourceFile : console.error("Action not chosen."); | ||
action ? _sourceFile = parseUrl(sourceFile) : logErr("Action not chosen."); | ||
stdio.question(`What file do you want to ${action} to. (PLEASE INCUDE FILE EXTENSION EG. /file.txt)`, (err, destinationFile) => { | ||
stdio.question(`What file do you want to ${action} to. (PLEASE INCUDE FILE EXTENSION EG. FullFilePath.txt)`, (err, destinationFile) => { | ||
action ? _destinationFile = destinationFile : console.error("Action not chosen."); | ||
action ? _destinationFile = parseUrl(destinationFile) : logErr("Action not chosen."); | ||
console.log(`The file ${sourceFile} will be ${action}ed and saved to ${destinationFile}`); | ||
log(`The file ${_sourceFile} will be ${action}ed and saved to ${_destinationFile}`); | ||
stdio.question("Enter your Key", (err, key) => { | ||
const keyFile = `${_destinationFile}___KEY.txt`; | ||
//write key to key.txt file | ||
fs.writeFile("key.txt", key, (err) => { | ||
fs.writeFile(keyFile, key, (err) => { | ||
if(err){ console.error(`Error => ${err}`); return } | ||
if(err){ logErr(`Error => ${err}`); return } | ||
console.log("Key has been written to /key.txt"); | ||
log(`Key has been written to ${keyFile}`); | ||
}); | ||
//encrpt or decrypt file | ||
//ENCRYPT or DECRYPT file | ||
@@ -146,5 +201,5 @@ if(key){ | ||
if(action === "Encrypt") { console.log( cipher( _sourceFile, key )); } | ||
if(action === "Encrypt") { log( cipher( _sourceFile, key )); } | ||
if(action === "Decrypt") { console.log( decipher( _sourceFile, key )); } | ||
if(action === "Decrypt") { log( decipher( _sourceFile, key )); } | ||
@@ -154,3 +209,3 @@ | ||
console.error("Key cannot be Empty"); | ||
logErr("Key cannot be Empty"); | ||
} | ||
@@ -166,2 +221,5 @@ | ||
//run the user action helper/wizard | ||
function run(){ | ||
@@ -182,3 +240,3 @@ | ||
console.log("Pease Enter a valid answer/action to proceed or press [shift]+[C] to cancel."); | ||
log("Pease Enter a valid answer/action to proceed or press [shift]+[C] to cancel."); | ||
@@ -188,7 +246,6 @@ } | ||
}); | ||
} | ||
//Auto test | ||
//recreate(filePath); | ||
run(); |
{ | ||
"name": "caxhcipher", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Encrypt any file with top notch encryption of your choice from hundreds of options.100% Configuration.", | ||
"main": "app.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/cacious7/caxhcipher.git" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"cipher": "node app.js" | ||
"cipher": "node app.js", | ||
"ciphers": "node getCiphers.js" | ||
}, | ||
@@ -19,3 +16,3 @@ "keywords": [ | ||
"Cipher", | ||
"fs && crypto implementation" | ||
"Program" | ||
], | ||
@@ -22,0 +19,0 @@ "author": "Cacious Siamunyanga", |
@@ -1,2 +0,23 @@ | ||
# caxhcipher | ||
Encrypt any file with top notch encryption of your choice from hundreds of options.100% Configuration. | ||
# <h1>CAXHCIPHER</h1> | ||
Encrypt any file with top notch encryption of your choice from hundreds of options.100% Configurable. | ||
# <h3>CHOOSING CIPHER ALGORITHM</h3> | ||
+ Open cipherMethod.js | ||
+ Select a cipher method from the options commented out below | ||
# <h3>INSTALL CAXHCIPHER</h3> | ||
+ Open comand prompt from the directory you want to save caxhcipher | ||
+ Type " npm install caxhciper " | ||
+ Clone the <a href="https://github.com/cacious7/caxhcipher" target="_blank" title="caxhcipher git repository" alt="caxhcipher git | ||
repository"><strong>caxhcipher git repository</strong></a> | ||
# <h3>RUNNING THE ACTION WIZARD(ENCRYPT / DECRYPT WIZARD)</h3> | ||
+ Open command prompt from caxhcipher module folder | ||
+ " npm run cipher " | ||
+ " node app.js " | ||
# <h3>VIEW AVAILABLE CIPHER ALGORITHMS</h3> | ||
+ Open command promt from caxhcipher module folder | ||
+ " npm run ciphers " | ||
+ " node getCiphers.js" | ||
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
45674
7
259
24
2
1