wilcocrypt 1.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ import{createCipheriv as t,createDecipheriv as e,randomBytes as s,scryptSync as r}from"crypto";import{gzipSync as f,gunzipSync as n}from"zlib";import{readFileSync as i,writeFileSync as o}from"fs";var h,a,u,c,l,p,d,b={};function E(){if(p)return l;p=1;const t=new(function(){if(c)return u;c=1;const t=process.env.NOTEPACK_DECODE_KEY_CACHE_MAX_SIZE||1024,e=process.env.NOTEPACK_DECODE_KEY_CACHE_MAX_LENGTH||16;return u=class{constructor({maxSize:s=t,maxLength:r=e}={}){this.size=0,this.maxSize=s,this.maxLength=r,this.cache=new Map;for(let t=1;t<=this.maxLength;t++)this.cache.set(t,new Map)}get(t,e,s){if(s>this.maxLength)return!1;let r=this.cache.get(s);for(let f=0;f<s;f++){const s=t[e+f];if(!r.has(s))return!1;r=r.get(s)}return r}set(t,e,s,r){if(s>this.maxLength||this.size>=this.maxSize)return;this.size++;let f=this.cache.get(s);for(let n=0;n<s;n++){const i=t[e+n];if(n===s-1)f.set(i,r);else if(f.has(i))f=f.get(i);else{const t=new Map;f.set(i,t),f=t}}}}}());function e(t){this.offset=0,this.buffer=t,this.useKeyCache=!1}return e.prototype.array=function(t){const e=new Array(t);for(let s=0;s<t;s++)e[s]=this.parse();return e},e.prototype.map=function(t){let e="",s={};for(let r=0;r<t;r++)this.useKeyCache=!0,e=this.parse(),this.useKeyCache=!1,s[e]=this.parse();return s},e.prototype.str=function(e){if(this.useKeyCache){const s=t.get(this.buffer,this.offset,e);if(s)return this.offset+=e,s}const s=this.buffer.toString("utf8",this.offset,this.offset+e);return this.useKeyCache&&t.set(this.buffer,this.offset,e,s),this.offset+=e,s},e.prototype.bin=function(t){const e=this.buffer.slice(this.offset,this.offset+t);return this.offset+=t,e},e.prototype.arraybuffer=function(t){const e=new ArrayBuffer(t),s=new Uint8Array(e);for(let e=0;e<t;e++)s[e]=this.buffer[this.offset+e];return this.offset+=t,e},e.prototype.parse=function(){const t=this.buffer[this.offset++];let e,s=0,r=0,f=0,n=0;if(t<192)return t<128?t:t<144?this.map(15&t):t<160?this.array(15&t):this.str(31&t);if(t>223)return-1*(255-t+1);switch(t){case 192:return null;case 194:return!1;case 195:return!0;case 196:return s=this.buffer.readUInt8(this.offset),this.offset+=1,this.bin(s);case 197:return s=this.buffer.readUInt16BE(this.offset),this.offset+=2,this.bin(s);case 198:return s=this.buffer.readUInt32BE(this.offset),this.offset+=4,this.bin(s);case 199:if(s=this.buffer.readUInt8(this.offset),r=this.buffer.readInt8(this.offset+1),this.offset+=2,0===r)return this.arraybuffer(s);if(-1===r){const t=this.buffer.readUInt32BE(this.offset);return f=this.buffer.readInt32BE(this.offset+4),n=this.buffer.readUInt32BE(this.offset+8),this.offset+=12,new Date(1e3*(4294967296*f+n)+t/1e6)}return[r,this.bin(s)];case 200:return s=this.buffer.readUInt16BE(this.offset),r=this.buffer.readInt8(this.offset+2),this.offset+=3,0===r?this.arraybuffer(s):[r,this.bin(s)];case 201:return s=this.buffer.readUInt32BE(this.offset),r=this.buffer.readInt8(this.offset+4),this.offset+=5,0===r?this.arraybuffer(s):[r,this.bin(s)];case 202:return e=this.buffer.readFloatBE(this.offset),this.offset+=4,e;case 203:return e=this.buffer.readDoubleBE(this.offset),this.offset+=8,e;case 204:return e=this.buffer.readUInt8(this.offset),this.offset+=1,e;case 205:return e=this.buffer.readUInt16BE(this.offset),this.offset+=2,e;case 206:return e=this.buffer.readUInt32BE(this.offset),this.offset+=4,e;case 207:return f=this.buffer.readUInt32BE(this.offset)*Math.pow(2,32),n=this.buffer.readUInt32BE(this.offset+4),this.offset+=8,f+n;case 208:return e=this.buffer.readInt8(this.offset),this.offset+=1,e;case 209:return e=this.buffer.readInt16BE(this.offset),this.offset+=2,e;case 210:return e=this.buffer.readInt32BE(this.offset),this.offset+=4,e;case 211:return f=this.buffer.readInt32BE(this.offset)*Math.pow(2,32),n=this.buffer.readUInt32BE(this.offset+4),this.offset+=8,f+n;case 212:return r=this.buffer.readInt8(this.offset),this.offset+=1,0===r?void(this.offset+=1):[r,this.bin(1)];case 213:return r=this.buffer.readInt8(this.offset),this.offset+=1,[r,this.bin(2)];case 214:return r=this.buffer.readInt8(this.offset),this.offset+=1,-1===r?(e=this.buffer.readUInt32BE(this.offset),this.offset+=4,new Date(1e3*e)):[r,this.bin(4)];case 215:if(r=this.buffer.readInt8(this.offset),this.offset+=1,0===r)return f=this.buffer.readInt32BE(this.offset)*Math.pow(2,32),n=this.buffer.readUInt32BE(this.offset+4),this.offset+=8,new Date(f+n);if(-1===r){f=this.buffer.readUInt32BE(this.offset),n=this.buffer.readUInt32BE(this.offset+4),this.offset+=8;return new Date(1e3*(4294967296*(3&f)+n)+(f>>>2)/1e6)}return[r,this.bin(8)];case 216:return r=this.buffer.readInt8(this.offset),this.offset+=1,[r,this.bin(16)];case 217:return s=this.buffer.readUInt8(this.offset),this.offset+=1,this.str(s);case 218:return s=this.buffer.readUInt16BE(this.offset),this.offset+=2,this.str(s);case 219:return s=this.buffer.readUInt32BE(this.offset),this.offset+=4,this.str(s);case 220:return s=this.buffer.readUInt16BE(this.offset),this.offset+=2,this.array(s);case 221:return s=this.buffer.readUInt32BE(this.offset),this.offset+=4,this.array(s);case 222:return s=this.buffer.readUInt16BE(this.offset),this.offset+=2,this.map(s);case 223:return s=this.buffer.readUInt32BE(this.offset),this.offset+=4,this.map(s)}throw new Error("Could not parse")},l=function(t){const s=new e(t),r=s.parse();if(s.offset!==t.length)throw new Error(t.length-s.offset+" trailing bytes");return r}}var I=(d||(d=1,b.encode=function(){if(a)return h;function t(t,e,s){let r=0;for(let f=0,n=s.length;f<n;f++)r=s.charCodeAt(f),r<128?t[e++]=r:r<2048?(t[e++]=192|r>>6,t[e++]=128|63&r):r<55296||r>=57344?(t[e++]=224|r>>12,t[e++]=128|r>>6&63,t[e++]=128|63&r):(f++,r=65536+((1023&r)<<10|1023&s.charCodeAt(f)),t[e++]=240|r>>18,t[e++]=128|r>>12&63,t[e++]=128|r>>6&63,t[e++]=128|63&r)}a=1;const e=new Map,s=process.env.NOTEPACK_ENCODE_CACHE_MAX_SIZE||1024;function r(r,n,i){if(e.has(i)){const t=e.get(i);return n.push({bin:t,length:t.length,offset:r.length}),t.length}if(e.size>s)return f(r,n,i);const o=[],h=f(o,[],i),a=Buffer.allocUnsafe(h);for(let t=0,e=o.length;t<e;t++)a[t]=o[t];return t(a,o.length,i),n.push({bin:a,length:h,offset:r.length}),e.set(i,a),h}function f(t,e,s){let n=0,i=0,o=0,h=0;switch(typeof s){case"string":if(o=s.length>32?Buffer.byteLength(s):function(t){let e=0,s=0;for(let r=0,f=t.length;r<f;r++)e=t.charCodeAt(r),e<128?s+=1:e<2048?s+=2:e<55296||e>=57344?s+=3:(r++,s+=4);return s}(s),o<32)t.push(160|o),h=1;else if(o<256)t.push(217,o),h=2;else if(o<65536)t.push(218,o>>8,o),h=3;else{if(!(o<4294967296))throw new Error("String too long");t.push(219,o>>24,o>>16,o>>8,o),h=5}return e.push({str:s,length:o,offset:t.length}),h+o;case"number":return Math.floor(s)===s&&isFinite(s)?s>=0?s<128?(t.push(s),1):s<256?(t.push(204,s),2):s<65536?(t.push(205,s>>8,s),3):s<4294967296?(t.push(206,s>>24,s>>16,s>>8,s),5):(n=s/Math.pow(2,32)|0,i=s>>>0,t.push(207,n>>24,n>>16,n>>8,n,i>>24,i>>16,i>>8,i),9):s>=-32?(t.push(s),1):s>=-128?(t.push(208,s),2):s>=-32768?(t.push(209,s>>8,s),3):s>=-2147483648?(t.push(210,s>>24,s>>16,s>>8,s),5):(n=Math.floor(s/Math.pow(2,32)),i=s>>>0,t.push(211,n>>24,n>>16,n>>8,n,i>>24,i>>16,i>>8,i),9):(t.push(203),e.push({float:s,length:8,offset:t.length}),9);case"object":if(null===s)return t.push(192),1;if(Array.isArray(s)){if(o=s.length,o<16)t.push(144|o),h=1;else if(o<65536)t.push(220,o>>8,o),h=3;else{if(!(o<4294967296))throw new Error("Array too large");t.push(221,o>>24,o>>16,o>>8,o),h=5}for(let r=0;r<o;r++)h+=f(t,e,s[r]);return h}if(s instanceof Date){const e=s.getTime(),r=Math.floor(e/1e3),f=1e6*(e-1e3*r);return r>=0&&f>=0&&r<=17179869183?0===f&&r<=4294967295?(t.push(214,255,r>>24,r>>16,r>>8,r),6):(n=r/4294967296,i=4294967295&r,t.push(215,255,f>>22,f>>14,f>>6,n,i>>24,i>>16,i>>8,i),10):(n=Math.floor(r/4294967296),i=r>>>0,t.push(199,12,255,f>>24,f>>16,f>>8,f,n>>24,n>>16,n>>8,n,i>>24,i>>16,i>>8,i),15)}if(s instanceof Buffer){if(o=s.length,o<256)t.push(196,o),h=2;else if(o<65536)t.push(197,o>>8,o),h=3;else{if(!(o<4294967296))throw new Error("Buffer too large");t.push(198,o>>24,o>>16,o>>8,o),h=5}return e.push({bin:s,length:o,offset:t.length}),h+o}if(s instanceof ArrayBuffer||ArrayBuffer.isView(s))return f(t,e,Buffer.from(s));if("function"==typeof s.toJSON)return f(t,e,s.toJSON());const a=[],u=Object.keys(s);let c="";for(let t=0,e=u.length;t<e;t++)c=u[t],void 0!==s[c]&&"function"!=typeof s[c]&&a.push(c);if(o=a.length,o<16)t.push(128|o),h=1;else if(o<65536)t.push(222,o>>8,o),h=3;else{if(!(o<4294967296))throw new Error("Object too large");t.push(223,o>>24,o>>16,o>>8,o),h=5}for(let n=0;n<o;n++)c=a[n],h+=r(t,e,c),h+=f(t,e,s[c]);return h;case"boolean":return t.push(s?195:194),1;case"undefined":return t.push(192),1;default:if("function"==typeof s.toJSON)return f(t,e,s.toJSON());throw new Error("Could not encode")}}return h=function(e){const s=[],r=[],n=f(s,r,e),i=Buffer.allocUnsafe(n);let o=0,h=0,a=-1;r.length>0&&(a=r[0].offset);let u,c=0,l=0;for(let e=0,f=s.length;e<f;e++)for(i[h+e]=s[e];e+1===a;){if(u=r[o],c=u.length,l=h+a,u.bin)if(c>32)u.bin.copy(i,l,0,c);else{const t=u.bin;for(let e=0;e<c;e++)i[l+e]=t[e]}else u.str?c>32?i.write(u.str,l,c,"utf8"):t(i,l,u.str):void 0!==u.float&&i.writeDoubleBE(u.float,l);if(o++,h+=c,!r[o])break;a=r[o].offset}return i}}(),b.decode=E()),b);const g={_:{}};class y extends Error{constructor(t,e="WILCOCRYPT_ERROR"){super(t),this.name="WilcoCryptError",this.code=e,Error.captureStackTrace&&Error.captureStackTrace(this,y)}}g._.WilcoCryptError=y,g._.VERSION="2.1.0",g._.MIN_PASSWORD_LENGTH=6,g._.assertKeyAndIv=function(t,e){if(!Buffer.isBuffer(t)||32!==t.length)throw new y("Invalid encryption key (expected 32-byte Buffer)","INVALID_KEY");if(!Buffer.isBuffer(e)||12!==e.length)throw new y("Invalid IV (expected 12-byte Buffer for GCM)","INVALID_IV")},g._.assertPassword=function(t){if("string"!=typeof t||t.length<g._.MIN_PASSWORD_LENGTH)throw new y(`Password must be at least ${g._.MIN_PASSWORD_LENGTH} characters`,"WEAK_PASSWORD")},g._.constantTimeEqual=function(t,e){if(t.length!==e.length)return!1;let s=0;for(let r=0;r<t.length;r++)s|=t[r]^e[r];return 0===s},g._.encryptData=function(e,s,r){g._.assertKeyAndIv(s,r);const f=t("aes-256-gcm",s,r);return{ciphertext:Buffer.concat([f.update(e),f.final()]),authTag:f.getAuthTag()}},g._.decryptData=function(t,s,r,f){g._.assertKeyAndIv(r,f);try{const n=e("aes-256-gcm",r,f);return n.setAuthTag(Buffer.from(s,"hex")),Buffer.concat([n.update(Buffer.from(t,"hex")),n.final()])}catch{throw new y("Decryption failed (invalid password, corrupted data, or tampered file)","DECRYPTION_FAILED")}},g.encryptData=function(t,e,n=!0){let i;g._.assertPassword(e),i=n?f(t):t;const o=s(12),h=s(16),a=r(e,h,32),{ciphertext:u,authTag:c}=g._.encryptData(i,a,o),l={payload:u.toString("hex"),authTag:c.toString("hex"),salt:h.toString("hex"),iv:o.toString("hex"),version:g._.VERSION};return I.encode(l)},g.decryptData=function(t,e,s=!0){let f;g._.assertPassword(e);try{f=I.decode(t)}catch{throw new y("Invalid encrypted data format (not MessagePack)","INVALID_FORMAT")}if(f.version!==g._.VERSION)throw new y(`Version mismatch (expected ${g._.VERSION}, got ${f.version})`,"VERSION_MISMATCH");const i=r(e,Buffer.from(f.salt,"hex"),32),o=g._.decryptData(f.payload,f.authTag,i,Buffer.from(f.iv,"hex"));try{return s?n(o):o}catch{throw new y("Decryption succeeded but decompression failed (data may be corrupted or not compressed)","DECOMPRESSION_FAILED")}},g.encryptFile=function(t,e,s=!0){const r=i(t),f=g.encryptData(r,e,s);o(`${t}.enc`,f)},g.decryptFile=function(t,e,s=!0){if(!t.endsWith(".enc"))throw new y("Invalid file extension (expected .enc)","INVALID_FILE_EXTENSION");const r=i(t);return g.decryptData(r,e,s)};export{g as default};
package/package.json CHANGED
@@ -1,18 +1,35 @@
1
1
  {
2
2
  "name": "wilcocrypt",
3
- "version": "1.0.0",
4
- "description": "A encrypt tool for JS",
5
- "license": "ISC",
3
+ "version": "2.1.0",
4
+ "description": "A encrypting tool",
5
+ "keywords": [
6
+ "encrypting"
7
+ ],
8
+ "license": "GPL-3.0-only",
6
9
  "author": "Wilco Joosen",
7
- "type": "commonjs",
8
- "main": "main.js",
10
+ "type": "module",
11
+ "main": "dist/wilcocrypt.min.js",
12
+ "bin": "dist/cli.min.js",
9
13
  "scripts": {
10
- "test": "node test/test.js",
11
- "update": "npx -y Jelmerro/nus"
14
+ "test": "echo \"Error: no test specified\" && exit 1",
15
+ "update": "npx -y Jelmerro/nus",
16
+ "rollup": "rollup -c && node src/scripts/fix-cli-min-import.js && node src/scripts/chmod.js",
17
+ "sea:blob": "node src/scripts/sea-blob.js",
18
+ "sea:linux-x64": "cp node-binaries/linux-x64/node release/wilcocrypt-linux-x64 && npx postject release/wilcocrypt-linux-x64 NODE_SEA_BLOB sea/wilcocrypt.sea --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 && chmod +x release/wilcocrypt-linux-x64",
19
+ "sea:linux-arm64": "cp node-binaries/linux-arm64/node release/wilcocrypt-linux-arm64 && npx postject release/wilcocrypt-linux-arm64 NODE_SEA_BLOB sea/wilcocrypt.sea --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 && chmod +x release/wilcocrypt-linux-arm64",
20
+ "sea:windows-x64": "cp node-binaries/windows-x64/node.exe release/wilcocrypt-windows-x64.exe && npx postject release/wilcocrypt-windows-x64.exe NODE_SEA_BLOB sea/wilcocrypt.sea --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2",
21
+ "sea:macos-x64": "cp node-binaries/macos-x64/node release/wilcocrypt-macos-x64 && npx postject release/wilcocrypt-macos-x64 NODE_SEA_BLOB sea/wilcocrypt.sea --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 && chmod +x release/wilcocrypt-macos-x64",
22
+ "sea:macos-arm64": "cp node-binaries/macos-arm64/node release/wilcocrypt-macos-arm64 && npx postject release/wilcocrypt-macos-arm64 NODE_SEA_BLOB sea/wilcocrypt.sea --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 && chmod +x release/wilcocrypt-macos-arm64",
23
+ "build": "npm run rollup && npm run sea:blob && npm run sea:linux-x64 && npm run sea:linux-arm64 && npm run sea:windows-x64 && npm run sea:macos-x64 && npm run sea:macos-arm64",
24
+ "clean": "rm -rf dist && rm -rf sea/*.sea && rm -rf release/*"
12
25
  },
13
- "dependencies": {
14
- "fs-extra": "11.3.0",
15
- "javascript-obfuscator": "4.1.1",
16
- "logginglog": "^1.0.0"
26
+ "devDependencies": {
27
+ "@rollup/plugin-commonjs": "29.0.2",
28
+ "@rollup/plugin-node-resolve": "16.0.3",
29
+ "@rollup/plugin-replace": "6.0.3",
30
+ "@rollup/plugin-terser": "1.0.0",
31
+ "commander": "14.0.3",
32
+ "notepack.io": "3.0.1",
33
+ "rollup": "4.60.2"
17
34
  }
18
35
  }
@@ -0,0 +1,54 @@
1
+ import { defineConfig } from 'rollup';
2
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
3
+ import commonjs from '@rollup/plugin-commonjs';
4
+ import replace from '@rollup/plugin-replace';
5
+ import terser from '@rollup/plugin-terser';
6
+ import { builtinModules } from 'module';
7
+
8
+ export default defineConfig([
9
+ {
10
+ input: {
11
+ wilcocrypt: 'src/wilcocrypt.js',
12
+ cli: 'src/cli.js'
13
+ },
14
+ output: [
15
+ {
16
+ dir: 'dist',
17
+ format: 'es',
18
+ entryFileNames: '[name].js',
19
+ banner: (chunk) => chunk.name === 'cli' ? '#!/usr/bin/env node' : null
20
+ },
21
+ {
22
+ dir: 'dist',
23
+ format: 'es',
24
+ entryFileNames: '[name].min.js',
25
+ banner: (chunk) => chunk.name === 'cli' ? '#!/usr/bin/env node' : null,
26
+ plugins: [terser()]
27
+ }
28
+ ],
29
+ external: [
30
+ ...builtinModules,
31
+ ...builtinModules.map(m => `node:${m}`)
32
+ ],
33
+ plugins: [
34
+ nodeResolve({ preferBuiltins: true }),
35
+ commonjs(),
36
+ replace({ preventAssignment: true, 'process.env.NODE_ENV': JSON.stringify('production') })
37
+ ]
38
+ },
39
+
40
+ {
41
+ input: 'src/cli.js',
42
+ output: {
43
+ file: 'dist/cli.min.cjs',
44
+ format: 'cjs',
45
+ banner: '#!/usr/bin/env node'
46
+ },
47
+ plugins: [
48
+ nodeResolve({ preferBuiltins: true }),
49
+ commonjs(),
50
+ replace({ preventAssignment: true, 'process.env.NODE_ENV': JSON.stringify('production') }),
51
+ terser()
52
+ ]
53
+ }
54
+ ]);
@@ -0,0 +1,5 @@
1
+ {
2
+ "main": "./dist/cli.min.cjs",
3
+ "output": "./sea/wilcocrypt.sea",
4
+ "disableExperimentalSEAWarning": true
5
+ }
package/encryption.js DELETED
@@ -1,103 +0,0 @@
1
- const crypto = require("crypto");
2
- const fs = require("fs-extra");
3
- const path = require("path");
4
- const JavaScriptObfuscator = require('javascript-obfuscator');
5
-
6
- const encryptHeader = "Wilco's Encryption Script V1.0.0\n";
7
-
8
- function deriveKey(keyNumber) {
9
- const keyBuffer = Buffer.from(String(keyNumber));
10
- return crypto.createHash('sha256').update(keyBuffer).digest();
11
- }
12
-
13
- /**
14
- *
15
- * @param {any} value
16
- * @param {String} encryptionKey
17
- */
18
-
19
- function encrypt(value, encryptionKey) {
20
- const encryptableValue = encryptHeader + JSON.stringify(value);
21
- const encryptionNum = encryptionKey.split("").map(char => char.charCodeAt(0)).join("");
22
- const key = deriveKey(encryptionNum);
23
- const iv = crypto.randomBytes(16);
24
- const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
25
- let encrypted = cipher.update(encryptableValue, 'utf8', 'hex');
26
- encrypted += cipher.final('hex');
27
- return iv.toString('hex') + encrypted;
28
- }
29
-
30
- /**
31
- *
32
- * @param {String} encryptedValue
33
- * @param {String} encryptionKey
34
- */
35
-
36
- function decrypt(encryptedValue, encryptionKey) {
37
- const keyNumber = encryptionKey.split("").map(char => char.charCodeAt(0)).join("");
38
- const key = deriveKey(keyNumber);
39
- const iv = Buffer.from(encryptedValue.slice(0, 32), 'hex');
40
- const encryptedText = encryptedValue.slice(32);
41
- const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
42
- let decrypted = decipher.update(encryptedText, 'hex', 'utf8');
43
- decrypted += decipher.final('utf8');
44
- if (!decrypted.startsWith(encryptHeader)) {
45
- throw new Error("decryption key is invalid");
46
- }
47
- const lst = decrypted.split(encryptHeader);
48
- lst.shift();
49
- return JSON.parse(lst.join(encryptHeader));
50
- }
51
-
52
- function encryptFileSync(file, encryptionKey, shouldObfiscate = false) {
53
- let res = fs.readFileSync(file).toString();
54
- if (shouldObfiscate) {
55
- res = JavaScriptObfuscator.obfuscate(res).getObfuscatedCode();
56
- }
57
- // console.log(res);
58
- return encrypt(res, encryptionKey);
59
- }
60
-
61
- function decryptFileSync(file, encryptionKey) {
62
- return decrypt(fs.readFileSync(file).toString(), encryptionKey);
63
- }
64
-
65
- function encryptDirSync(dir, encryptionKey) {
66
- /**
67
- *
68
- * @param {String} dir
69
- * @returns {{type: String, name: String, contents?: String|tree.returns}}
70
- */
71
- function tree(dir) {
72
- const objects = [];
73
- // console.log(dir);
74
- const files = fs.readdirSync(dir);
75
- for (const file of files) {
76
- if (fs.lstatSync(path.join(dir, file)).isDirectory()) {
77
- if (file !== "node_modules") {
78
- objects.push({
79
- type: "directory",
80
- name: file,
81
- contents: tree(path.join(dir, file))
82
- });
83
- }
84
- } else {
85
- objects.push({
86
- type: "file",
87
- name: file,
88
- contents: fs.readFileSync(path.join(dir, file))
89
- })
90
- }
91
- }
92
- return objects;
93
- }
94
- return encrypt(tree(dir), encryptionKey);
95
- }
96
-
97
- module.exports = {
98
- encrypt,
99
- decrypt,
100
- encryptFileSync,
101
- decryptFileSync,
102
- encryptDirSync
103
- }
package/main.js DELETED
@@ -1,55 +0,0 @@
1
- const { randomUUID } = require("crypto");
2
- const fs = require("fs-extra");
3
- const path = require("path");
4
- const logginglog = require("logginglog");
5
- const encryption = require("./encryption");
6
-
7
- const color = logginglog.colors();
8
- const serverlog = logginglog.makeLogger('WCrypt', color.rainbow);
9
-
10
- function encryptFile(keyFile, inputFile, outputDir) {
11
- keyFile = path.join(keyFile);
12
-
13
- fs.ensureFileSync(keyFile);
14
-
15
- const json = fs.readJSONSync(keyFile);
16
-
17
- const key = `WPKey ${randomUUID().replaceAll("-", " ")} ${randomUUID().replaceAll("-", " ")} ${randomUUID().replaceAll("-", " ")} ${randomUUID().replaceAll("-", " ")} ${randomUUID().replaceAll("-", " ")}`;
18
-
19
- json.key = key;
20
-
21
- fs.ensureDirSync(path.join(outputDir));
22
- fs.writeFileSync(path.join(outputDir, "main"), encryption.encryptFileSync(path.join(inputFile), key, true));
23
-
24
- fs.writeJsonSync(keyFile, json, {
25
- spaces: 4, EOL: '\r\n'
26
- });
27
-
28
- serverlog(`Uw code is succesvol gemaakt in ${path.join(__dirname, "encrypted", "main")}`);
29
- }
30
-
31
- function decryptLog(keyFile, outputDir) {
32
- let decrypted = fs.readFileSync(path.join(__dirname, "nokey.js")).toString();
33
-
34
- try {
35
- decrypted = encryption.decryptFileSync(path.join(outputDir, "main"), fs.readJSONSync(path.join(keyFile)).key);
36
- } catch (error) {
37
-
38
- }
39
-
40
- return decrypted;
41
- }
42
-
43
- function decryptFile(keyFile, outputDir) {
44
- const decrypted = decryptLog(keyFile, outputDir);
45
-
46
- const main = new Function('require', '__dirname', decrypted);
47
-
48
- return main;
49
- }
50
-
51
- module.exports = {
52
- encryptFile,
53
- decryptFile,
54
- decryptLog
55
- }
package/nokey.js DELETED
@@ -1,2 +0,0 @@
1
- console.log("ERROR key is either invalid or not provided, exitting...");
2
- process.exit(1);
package/test/config.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "key": "WPKey 65192ef5 f89d 4767 a155 fdacd7b2e977 3c97af72 96ae 4f23 86a2 48e39a70ab9c b5cd0a9f 7ac9 47ff b0e9 9b42819d4d8a 528095ff 04ea 4207 8274 f377b3944a5f da1aa5ae 9120 4d25 a5dd f9c5b745822d"
3
- }
package/test/decrypt.js DELETED
@@ -1,6 +0,0 @@
1
- const wilcocrypt = require("../main");
2
- const path = require("path");
3
-
4
- const main = wilcocrypt.decryptFile(path.join(__dirname, "config.json"), path.join(__dirname, "encrypted"));
5
-
6
- main(require, __dirname);
@@ -1,6 +0,0 @@
1
- const wilcocrypt = require("../main");
2
- const path = require("path");
3
-
4
- const decrypted = wilcocrypt.decryptLog(path.join(__dirname, "config.json"), path.join(__dirname, "encrypted"));
5
-
6
- console.log(decrypted);
package/test/encrypt.js DELETED
@@ -1,4 +0,0 @@
1
- const wilcocrypt = require("../main");
2
- const path = require("path");
3
-
4
- wilcocrypt.encryptFile(path.join(__dirname, "config.json"), path.join(__dirname, "test.js"), path.join(__dirname, "encrypted"));
@@ -1 +0,0 @@
1
- ec3d347f42dcb45872dbe11384511403442d24fe0c502e2070db8ca2fea0c3f9c2d1bb15c0f27a83ed128c545ee668f176d4c4c3ce78fe3c69f0979c80e9ee2e97533b2701b90cff18af9643441ccfde6b428c7746fd722ccf6b9290be12254b9a5d0bbbc121442d8a6077b8857c87788acfd00c0448e5e8edd28c093f1f24b016743aa13bbff1ecf0a6e7424307973d440f57cf3bc6b4770018c9e2effeaeb94b762975c526f44299d8734e1407ae994b27dabf6fed930ee0201e90812aa547b57cd75e718d96bb7915e2c1d37026b7bcec4c5c331a17b4f882f43f427ccf9b99a4ed51921bfdede2b40a493034e3016144bc1db0f93616e9bafcaf2e04623699d768ed6b099fc2a29820c39329de6e58e392c6ff43722b57f9bb3e006fbd0e4a5ba83ae7844b780dffd347115a070587def1a552ffbb3fa248a50d55a3e20b0632de552a83f995bf0697e963809d51d08c2cc3675d2d1e1427ac74279b40ebb5298576dec079b726e3ca1590c67119943ca3b265f3afe64df6acb1ddd5a285d8812bc1964c68a2c4fb69c9f0b4e4828ac7bd6778e5bac26da778aac5f5db727eb8da208cabad5f19f020125a71c6f1611f5e3e3add92e7b994c253eaf4becbb092309294952afae4e7bd2e16761b8d5f2ec1cafc5782ceaa0ee7cd1acd9cf7417a3a38f2ffc19f47c5c48dcecb240d83ad82fb16ea82633ac15a4c0af8aa614de5eaadbf550861c90aa2f1004957d96c3bf12c6ba3b766319a065bbf44b08e24576819249fa84b8583b4828d983338efa35f744fc75d9b3f96a23a552d655290cd0d3826cc24d883a39212c28addfcba95a0efcd5a8e14a56f08b17e5db749c063459a3e45d6c1ca89f86bc7d5fb5b6a0c745a27a918fc2169fdd9f6974d41f778a3078557d785d1b9bd0f40b890b1c21a7011f5ce8198b57603b219036400016c936a1b0e91a63037c7397d5d1a463a2ebf293c3217694c854a28d42cd3a08588470b2390a8df1d21f489cf68f279e8b45edf8f45d299ac6d50dc2f37139d17cba18ecb264783e1484b8e9bfa916820788371484f821a0a5464df34cbf95a6faab3bd4cfd128cc9acb57ef4f2893f96b324ee06968b199836797601d64c0670602cec99c561387399459114cf5c5a8556f7878538cbfddf95e2bfec6e3199120e8e8cde931a9816b86e3562185ab023e0fe2cd10f75685b03734f05380d9803c50bbe9bfc112ccfdb45e537e9b5e645536a0b6a5bf071722de3ef2522e0912b51c2cf5a1e268cd2207d242ce5797001d44482d0cc5931e84c7039674576f9d44b67739d1eaab7fd94e50cd191cc460f805cc27143834a37f76ccd65271ce2342f23c50806e509a2567982d008c5256bace9cb81b9f46e2b1c2d41bdb94b357227c3bc0e3f49eabd390d596cd1349a28d5a3c60e6e7ac65fdffabe797a6a4352f4ab67228f52c17dedd83a14f2faf2479757aac21818741c13323b27c12f18858ef2c3362ed730651ffdd64c166ffb53b8a2703d191b2160aaaf36aee571adc522cf148be4a7cb07eb58f3d702959c857e1b4fb9f80d8d616fbd98f1acb92a983bb480a43635b1ef6a47e471098974eb00babaee1127c0f3a4911b7d1f52d1
package/test/test.js DELETED
@@ -1 +0,0 @@
1
- console.log("Test");