node.js - 代码保护? [英] node.js - Code Protection?

查看:147
本文介绍了node.js - 代码保护?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的下一个项目中使用node.js,但我的老板不喜欢我们的竞争对手可以阅读源代码。

I want to use node.js in my next project, but my boss does not like that our competitors can read the source code.

有没有办法保护JavaScript代码?

Is there a way to protect the JavaScript code?

推荐答案

您可以使用节点的NativeExtension完成此操作

You could accomplish this with a NativeExtension for node

你有一个 boostrap.js 文件,为.jse文件添加扩展处理程序

You'd have a boostrap.js file that adds a extension handler for .jse files

// register extension
require.extensions[".jse"] = function (m) {
 m.exports = MyNativeExtension.decrypt(fs.readFileSync(m.filename));
};

require("YourCode.jse");

YourCode.jse 将是加密版本你的源代码(解密的密钥不会是纯文本的任何地方,因为解密过程发生在原生扩展中)。

YourCode.jse would be the encrypted version of your source code (the key for decryption wouldn't be anywhere in plain-text because the decryption process takes place in the native extension).

现在你有了NativeExtensions 解密函数将源转换回javascript。只需让您的构建过程创建所有文件的加密 .jse 版本,然后将这些版本发布给您的客户。他们还需要原生扩展,但现在你已经更难以修改代码了。您甚至可以将原生分机呼叫置于家中并检查许可证信息以帮助防止盗版(请记住,这不会阻止盗版,没有解决方案)。

Now you have your NativeExtensions decrypt function transform the source back to javascript. Just have your build process create encrypted .jse versions of all your files and release those to your customers. They'd also need the native extension but now you've made it a little harder to modify your code without too much effort. You can even make the native extension call home and check license information to help prevent piracy (keep in mind this won't stop piracy, there's no solution for that).

这篇关于node.js - 代码保护?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆