diff --git a/WelsonJS.Toolkit/WelsonJS.Toolkit/Toolkit.cs b/WelsonJS.Toolkit/WelsonJS.Toolkit/Toolkit.cs index 9fb6500..8c748c9 100644 --- a/WelsonJS.Toolkit/WelsonJS.Toolkit/Toolkit.cs +++ b/WelsonJS.Toolkit/WelsonJS.Toolkit/Toolkit.cs @@ -239,7 +239,7 @@ namespace WelsonJS byte[] dataIn = Convert.FromBase64String(encryptedData); HIGHT.ECB cipher = new HIGHT.ECB(userKey); - return Encoding.UTF8.GetString(cipher.Decrypt(dataIn)); + return Encoding.UTF8.GetString(cipher.Decrypt(dataIn)).Trim('\0'); } } } diff --git a/app.js b/app.js index d8dc075..9a69bca 100644 --- a/app.js +++ b/app.js @@ -307,20 +307,18 @@ function require(pathname) { break; case ".enc": // HIGHT(ISO/IEC 18033-3) encrypted - T = (function(encryptedData) { + T = (function(encryptedData, ToolkitInterface) { try { - var toolkit = CreateObject("WelsonJS.Toolkit"); var userKey = ''; while (userKey.length == 0 || userKey.length > 16) { - userKey = toolkit.Prompt("Enter the password:"); + userKey = ToolkitInterface.Prompt("This file has been encrypted. Please enter the password:"); } - return toolkit.DecryptStringHIGHT(encryptedData); + return ToolkitInterface.DecryptStringHIGHT(userKey, encryptedData); } catch (e) { console.error("Failed to load the encrypted data:", e.message); return ''; } - })(T); - + })(T, CreateObject("WelsonJS.Toolkit")); break; } @@ -331,6 +329,8 @@ function require(pathname) { + "\n\nreturn module.exports})(module.exports,global.require,module,__filename__,__dirname__)})(require.__global__);\n\n////@ sourceURL=" + FN ; + + if (suffix == ".enc") console.log(T); // execute try { diff --git a/bin/x64/WelsonJS.Toolkit.dll b/bin/x64/WelsonJS.Toolkit.dll index cf6a742..c615182 100644 Binary files a/bin/x64/WelsonJS.Toolkit.dll and b/bin/x64/WelsonJS.Toolkit.dll differ diff --git a/bin/x64/WelsonJS.Toolkit.pdb b/bin/x64/WelsonJS.Toolkit.pdb index cba2e57..70b7ed0 100644 Binary files a/bin/x64/WelsonJS.Toolkit.pdb and b/bin/x64/WelsonJS.Toolkit.pdb differ diff --git a/bin/x86/WelsonJS.Toolkit.dll b/bin/x86/WelsonJS.Toolkit.dll index 495cb41..d787330 100644 Binary files a/bin/x86/WelsonJS.Toolkit.dll and b/bin/x86/WelsonJS.Toolkit.dll differ diff --git a/bin/x86/WelsonJS.Toolkit.pdb b/bin/x86/WelsonJS.Toolkit.pdb index cba2e57..70b7ed0 100644 Binary files a/bin/x86/WelsonJS.Toolkit.pdb and b/bin/x86/WelsonJS.Toolkit.pdb differ diff --git a/encryptor.js b/encryptor.js new file mode 100644 index 0000000..f49e3ff --- /dev/null +++ b/encryptor.js @@ -0,0 +1,30 @@ +// encryptor.js +// HIGHT(ISO/IEC 18033-3) encryption and decryption tool for WelsonJS +// Namhyeon Go +// https://github.com/gnh1201/welsonjs + +var FILE = require("lib/file"); +var Toolkit = require("lib/toolkit"); + +function main(args) { + if (args.length < 1) { + console.error("Usage: cscript app.js encryptor "); + return 0; + } + + var filename = args[0]; + var userKey = ''; + while (userKey.length == 0 || userKey.length > 16) { + userKey = Toolkit.prompt("Please enter the password for encryption:"); + } + var data = FILE.readFile(filename, "utf-8"); + var encryptedData = Toolkit.encryptStringHIGHT(userKey, data); + + var dstfile = filename + ".enc"; + FILE.writeFile(dstfile, encryptedData, "utf-8"); + console.log("Saved to", dstfile); + + console.log("Done"); +} + +exports.main = main; diff --git a/lib/toolkit.js b/lib/toolkit.js index f565d18..d6f8f2c 100644 --- a/lib/toolkit.js +++ b/lib/toolkit.js @@ -92,6 +92,14 @@ function closeProcess(pid) { return getInterface().CloseProcess(pid); } +function encryptStringHIGHT(userKey, data) { + return getInterface().EncryptStringHIGHT(userKey, data); +} + +function decryptStringHIGHT(userKey, encryptedData) { + return getInterface().DecryptStringHIGHT(userKey, encryptedData); +} + exports.create = create; exports.getInterface = getInterface; exports.sendClick = sendClick; @@ -103,8 +111,10 @@ exports.prompt = prompt; exports.NamedSharedMemory = NamedSharedMemory; exports.openProcess = openProcess; exports.closeProcess = closeProcess; +exports.encryptStringHIGHT = encryptStringHIGHT; +exports.decryptStringHIGHT = decryptStringHIGHT; -exports.VERSIONINFO = "WelsonJS.Toolkit Native API version 0.3.4"; +exports.VERSIONINFO = "WelsonJS native component (WelsonJS.Toolkit) version 0.3.5"; exports.AUTHOR = "abuse@catswords.net"; exports.global = global; exports.require = global.require;