• Node.JS中调用JShaman,加密JS代码


    在Node.JS环境中,调用JShaman的WebAPI接口,对JS代码进行混淆加密。

    效果如下:

     

    代码:

     

    1. //js代码
    2. var js_code = `
    3. function NewObject(prefix)
    4. {
    5. var count=0;
    6. this.SayHello=function(msg)
    7. {
    8. count++;
    9. alert(prefix+msg);
    10. }
    11. this.GetCount=function()
    12. {
    13. return count;
    14. }
    15. }
    16. var obj=new NewObject("Message : ");
    17. obj.SayHello("You are welcome.");
    18. `;
    19. //配置,配置信息请关注JShaman官网,可能会有更新
    20. var config = {
    21. "part_variable_identifier_obfuscate": 1,
    22. "global_variable_identifier_obfuscate": 0,
    23. "part_function_identifier_obfuscate":0,
    24. "global_function_identifier_obfuscate": 0,
    25. "member_expression_encode": 1,
    26. "numberic_literal_encode": 1,
    27. "binary_express_obfuscate": 1,
    28. "boolean_encode": 1,
    29. "json_encode":1,
    30. "string_unicode_encode": 1,
    31. "assignment_junk_code":1,
    32. "zombie_code": 1,
    33. "eval_encode": 1,
    34. "control_flow": 1,
    35. "comma_operator": 1,
    36. "string_array": 1,
    37. "string_array_encode": 1,
    38. "vm_execute": 1,
    39. "ast_execute": 1,
    40. "no_beautifier": 1,
    41. "tamper_proof": 1,
    42. "comments": 0,
    43. "compress": 1,
    44. "reserved_word": ["jshaman","wlw"]
    45. }
    46. //同步request调用
    47. var jshaman_url = "http://www.jshaman.com:2080/obfuscate/";
    48. var request = require('sync-request');
    49. (function jf(js_code, config, jshaman_url){
    50. var res = request("POST", jshaman_url, {json:{
    51. "js_code":js_code,
    52. "vip_code":"free",
    53. "config":config
    54. }})
    55. var json_res = JSON.parse(res.getBody('utf8'));
    56. if(json_res.state == 0){
    57. //输出
    58. console.log(json_res.content);
    59. }
    60. }
    61. )(js_code,config,jshaman_url);

    为什么要对JS代码混淆加密?

    中文的说明很多了,引用一段老外的话语,看看外国人是怎样理解JS混淆加密必要性的:

    There are numerous reasons why it's a good idea to protect your code, such as:

    Prevent anyone from simply copy/pasting your work. This is specially important on 100% client side projects, such as HTML5 games;

    Removal of comments and whitespace that aren't needed. Making it faster to load and harder to understand;

    Protection of work that hasn't been paid for yet.

    You can show your work to the client knowing that they won't have the source code until the invoice has been paid.

    本例中,调用的是JShaman英文版的接口。

    JShaman是国内知名的JS代码保护服务提供商,JShaman英文版跟中文版功能是有差异的:

     

    主要是功能配置的不同:

     

    具体,请到JShaman官网了解。

  • 相关阅读:
    java毕业设计校园内推系统mybatis+源码+调试部署+系统+数据库+lw
    python+nodejs+vue火车票订票系统
    [附源码]计算机毕业设计基于springboot和vue的茶文化交流平台的设计与实现
    openEuler快速入门(二)-openEuler命令行基础操作
    QTextStream(文本流)
    【开源】SpringBoot框架开发新能源电池回收系统
    uniapp -从头开始开发小程序流程
    Swift 网络请求 Moya+RxSwift
    JavaScript基础之七JavaScript函数的使用
    【C基础篇】选择结构与循环控制
  • 原文地址:https://blog.csdn.net/w2sft/article/details/127816040