Node。JS中调用JShaman,加密JS代码
在Node。JS环境中,调用JShaman的WebAPI接口,对JS代码进行混淆加密。
效果如下:
代码:
js代码varjscodefunctionNewObject(prefix){varcount0;this。SayHellofunction(msg){count;alert(prefixmsg);}this。GetCountfunction(){returncount;}}varobjnewNewObject(Message:);obj。SayHello(Youarewelcome。);;配置,配置信息请关注JShaman官网,可能会有更新varconfig{partvariableidentifierobfuscate:1,globalvariableidentifierobfuscate:0,partfunctionidentifierobfuscate:0,globalfunctionidentifierobfuscate:0,memberexpressionencode:1,numbericliteralencode:1,binaryexpressobfuscate:1,booleanencode:1,jsonencode:1,stringunicodeencode:1,assignmentjunkcode:1,zombiecode:1,evalencode:1,controlflow:1,commaoperator:1,stringarray:1,stringarrayencode:1,vmexecute:1,astexecute:1,nobeautifier:1,tamperproof:1,comments:0,compress:1,reservedword:〔jshaman,wlw〕}同步request调用varjshamanurlhttp:www。jshaman。com:2080obfuscate;varrequestrequire(syncrequest);(functionjf(jscode,config,jshamanurl){varresrequest(POST,jshamanurl,{json:{jscode:jscode,vipcode:free,config:config}})varjsonresJSON。parse(res。getBody(utf8));if(jsonres。state0){输出console。log(jsonres。content);}})(jscode,config,jshamanurl);
为什么要对JS代码混淆加密?
中文的说明很多了,引用一段老外的话语,看看外国人是怎样理解JS混淆加密必要性的:Therearenumerousreasonswhyitsagoodideatoprotectyourcode,suchas:
Preventanyonefromsimplycopypastingyourwork。Thisisspeciallyimportanton100clientsideprojects,suchasHTML5games;
Removalofcommentsandwhitespacethatarentneeded。Makingitfastertoloadandhardertounderstand;
Protectionofworkthathasntbeenpaidforyet。
Youcanshowyourworktotheclientknowingthattheywonthavethesourcecodeuntiltheinvoicehasbeenpaid。
本例中,调用的是JShaman英文版的接口。
JShaman是国内知名的JS代码保护服务提供商,JShaman英文版跟中文版功能是有差异的:
主要是功能配置的不同:
具体,请到JShaman官网了解。