【如何才能保护我的 javascript 代码不被用户看到?】

nchen123 2004-08-16 01:44:42
How do I protect my client-side JavaScript code?

http://www.aspfaq.com/2175 created: 2001-08-16 last updated: 2001-10-30 19:26 this article is printer friendly
This has been asked thousands of times over the past few years. Everyone wants to know how they can prevent nosy people from viewing or stealing their JavaScript. I have always responded with:

"If my browser can read it, so can I."
"If you don't want people to steal your JavaScript, don't put it on the web."

I have also often thought the following:

"If your Javascript is so revolutionary, you should probably be able to figure this out too."
"And if someone does steal your script, consider it a compliment."


:)
...全文
420 37 打赏 收藏 转发到动态 举报
写回复
用AI写文章
37 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhuifengxiaozi 2004-09-10
  • 打赏
  • 举报
回复
什么秘密呀
  • 打赏
  • 举报
回复
噢.........................................................
nchen123 2004-09-10
  • 打赏
  • 举报
回复
阿泰, 还是你最了解我...
【木野狐】
阿泰 2004-09-10
  • 打赏
  • 举报
回复
技术是为了应用服务的,代码的共享可以让代码更完善.

国外的教育环境使人在看了代码后,会加以指正,再使用时会写上来源的作者
以示对原作者的尊重.
国内的大环境让很多人得到代码后不是去理解和提高,而是迫切的替换成自己的名字
抹杀原来的印记.
然后,又四处炫耀.

楼主着开篇的题目是为了让人注意,于是几乎没人去看文章的内容
所以大都是下笔千言,离题万里,呵呵.
这也是论坛的普遍现象~~~

nchen123 2004-09-09
  • 打赏
  • 举报
回复
很多人可能领会错我的意思了, 我怀疑你们有没有仔细看懂那段英文。

我的目的不是问如何保护客户端脚本, 而是劝告大家不要做这方面的无谓的尝试, 因为我看到太多人提这种问题了。
超级大笨狼 2004-08-17
  • 打赏
  • 举报
回复
Put the source on a floppy disk and bury it in a mason jar in your back yard. Make sure you delete all references to it from your system. To be extra sure, bury it blindfolded at night so you can't remember where it is in case foreign spies try to beat the location out of you.

Of course, you could write it as a Java Applet to make it tougher to figure out, but then, if you knew how to do that you'd probably also be able to write something really worth protecting...

超级大笨狼 2004-08-17
  • 打赏
  • 举报
回复
Microsoft's encoder was broken easily; perhaps you can write a better one
超级大笨狼 2004-08-17
  • 打赏
  • 举报
回复
脚本编码器是一种简单的命令行工具,它使脚本设计者可以对最终的脚本进行编码,从而使 Web 主机和 Web 客户不能查看或修改它们的源代码。注意,这种编码只能防止别人在无意中查看到您的代码,并不能防止蓄意黑客查看您的编码内容及其方法。
超级大笨狼 2004-08-17
  • 打赏
  • 举报
回复
哈哈,大家运行一下下面代码看是什么效果:)


<HTML>
<HEAD>
<TITLE>脚本编码器示例页</TITLE>
<SCRIPT LANGUAGE="JScript.Encode">#@~^SAAAAA==@#@&P~@#@&,lVDDcJ'E{ 9!w;F 0RwE+v 6w;c m-;v[WF-;GWT&'EWWZFJbI@#@&~@#@&4RAAAA==^#~@</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
超级大笨狼 2004-08-17
  • 打赏
  • 举报
回复
http://www.microsoft.com/downloads/details.aspx?displaylang=zh-cn&FamilyID=6A326D9C-F47E-4C92-B42A-B3D43029E96F

Script encoder
Script Encoder 是一个简单的命令行工具,脚本设计者可使用此工具对他们的最终脚本进行编码,从而使 Web 主机和 Web



快速信息
文件名:
sce10chs.exe

下载大小:
120 KB

发布日期:
2001-10-19

版本:
1.0


概述
Script Encoder 是一个简单的命令行工具,脚本设计者可使用此工具对他们的最终脚本进行编码,从而使 Web 主机和 Web 客户端无法查看或更改其源代码。注意,这种编码只能防止对您代码的一般性浏览,而无法防止专业黑客查看您的代码和实现方式。

Script encoder
简体中文

下载下载

--------------------------------------------------------------------------------
更改语言
韩语简体中文




相关资源

更多信息







--------------------------------------------------------------------------------

说明
您可选择“从当前位置运行此程序”立即开始下载,也可选择“保存到磁盘”将下载软件复制到您的机器并在以后再安装。
超级大笨狼 2004-08-17
  • 打赏
  • 举报
回复
魔高一尺道高一丈,不过。
超级大笨狼 2004-08-17
  • 打赏
  • 举报
回复
可以去下载一个微软的Windows s cript Encoder,它可以对asp的脚本和客户端javas cript/vbs cript脚本进行加密
超级大笨狼 2004-08-17
  • 打赏
  • 举报
回复
sBASE_64_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
sBASE_64_CHARACTERS = strUnicode2Ansi(sBASE_64_CHARACTERS)

Function strUnicodeLen(asContents)
'计算unicode字符串的Ansi编码的长度
asContents1="a"&asContents
len1=len(asContents1)
k=0
for i=1 to len1
asc1=asc(mid(asContents1,i,1))
if asc1<0 then asc1=65536+asc1
if asc1>255 then
k=k+2
else
k=k+1
end if
next
strUnicodeLen=k-1
End Function

Function strUnicode2Ansi(asContents)
'将Unicode编码的字符串,转换成Ansi编码的字符串
strUnicode2Ansi=""
len1=len(asContents)
for i=1 to len1
varchar=mid(asContents,i,1)
varasc=asc(varchar)
if varasc<0 then varasc=varasc+65536
if varasc>255 then
varHex=Hex(varasc)
varlow=left(varHex,2)
varhigh=right(varHex,2)
strUnicode2Ansi=strUnicode2Ansi & chrb("&H" & varlow ) & chrb("&H" & varhigh )
else
strUnicode2Ansi=strUnicode2Ansi & chrb(varasc)
end if
next
End function

Function strAnsi2Unicode(asContents)
'将Ansi编码的字符串,转换成Unicode编码的字符串
strAnsi2Unicode = ""
len1=lenb(asContents)
if len1=0 then exit function
for i=1 to len1
varchar=midb(asContents,i,1)
varasc=ascb(varchar)
if varasc > 127 then
strAnsi2Unicode = strAnsi2Unicode & chr(ascw(midb(asContents,i+1,1) & varchar))
i=i+1
else
strAnsi2Unicode = strAnsi2Unicode & chr(varasc)
end if
next
End function

Function Base64encode(asContents)
'将Ansi编码的字符串进行Base64编码
'asContents应当是ANSI编码的字符串(二进制的字符串也可以)
Dim lnPosition
Dim lsResult
Dim Char1
Dim Char2
Dim Char3
Dim Char4
Dim Byte1
Dim Byte2
Dim Byte3
Dim SaveBits1
Dim SaveBits2
Dim lsGroupBinary
Dim lsGroup64
Dim m4,len1,len2

len1=Lenb(asContents)
if len1<1 then
Base64encode=""
exit Function
end if

m3=Len1 Mod 3
If M3 > 0 Then asContents = asContents & String(3-M3, chrb(0))
'补足位数是为了便于计算

IF m3 > 0 THEN
len1=len1+(3-m3)
len2=len1-3
else
len2=len1
end if

lsResult = ""

For lnPosition = 1 To len2 Step 3
lsGroup64 = ""
lsGroupBinary = Midb(asContents, lnPosition, 3)

Byte1 = Ascb(Midb(lsGroupBinary, 1, 1)): SaveBits1 = Byte1 And 3
Byte2 = Ascb(Midb(lsGroupBinary, 2, 1)): SaveBits2 = Byte2 And 15
Byte3 = Ascb(Midb(lsGroupBinary, 3, 1))

Char1 = Midb(sBASE_64_CHARACTERS, ((Byte1 And 252) \ 4) + 1, 1)
Char2 = Midb(sBASE_64_CHARACTERS, (((Byte2 And 240) \ 16) Or (SaveBits1 * 16) And &HFF) + 1, 1)
Char3 = Midb(sBASE_64_CHARACTERS, (((Byte3 And 192) \ 64) Or (SaveBits2 * 4) And &HFF) + 1, 1)
Char4 = Midb(sBASE_64_CHARACTERS, (Byte3 And 63) + 1, 1)
lsGroup64 = Char1 & Char2 & Char3 & Char4

lsResult = lsResult & lsGroup64
Next

'处理最后剩余的几个字符
if M3 > 0 then
lsGroup64 = ""
lsGroupBinary = Midb(asContents, len2+1, 3)

Byte1 = Ascb(Midb(lsGroupBinary, 1, 1)): SaveBits1 = Byte1 And 3
Byte2 = Ascb(Midb(lsGroupBinary, 2, 1)): SaveBits2 = Byte2 And 15
Byte3 = Ascb(Midb(lsGroupBinary, 3, 1))

Char1 = Midb(sBASE_64_CHARACTERS, ((Byte1 And 252) \ 4) + 1, 1)
Char2 = Midb(sBASE_64_CHARACTERS, (((Byte2 And 240) \ 16) Or (SaveBits1 * 16) And &HFF) + 1, 1)
Char3 = Midb(sBASE_64_CHARACTERS, (((Byte3 And 192) \ 64) Or (SaveBits2 * 4) And &HFF) + 1, 1)

if M3=1 then
lsGroup64 = Char1 & Char2 & ChrB(61) & ChrB(61) '用=号补足位数
else
lsGroup64 = Char1 & Char2 & Char3 & ChrB(61) '用=号补足位数
end if

lsResult = lsResult & lsGroup64
end if

Base64encode = lsResult

End Function


Function Base64decode(asContents)
'将Base64编码字符串转换成Ansi编码的字符串
'asContents应当也是ANSI编码的字符串(二进制的字符串也可以)
Dim lsResult
Dim lnPosition
Dim lsGroup64, lsGroupBinary
Dim Char1, Char2, Char3, Char4
Dim Byte1, Byte2, Byte3
Dim M4,len1,len2

len1= Lenb(asContents)
M4 = len1 Mod 4

if len1 < 1 or M4 > 0 then
'字符串长度应当是4的倍数
Base64decode = ""
exit Function
end if

'判断最后一位是不是 = 号
'判断倒数第二位是不是 = 号
'这里m4表示最后剩余的需要单独处理的字符个数
if midb(asContents, len1, 1) = chrb(61) then m4=3
if midb(asContents, len1-1, 1) = chrb(61) then m4=2

if m4 = 0 then
len2=len1
else
len2=len1-4
end if

For lnPosition = 1 To Len2 Step 4
lsGroupBinary = ""
lsGroup64 = Midb(asContents, lnPosition, 4)
Char1 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 1, 1)) - 1
Char2 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 2, 1)) - 1
Char3 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 3, 1)) - 1
Char4 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 4, 1)) - 1
Byte1 = Chrb(((Char2 And 48) \ 16) Or (Char1 * 4) And &HFF)
Byte2 = lsGroupBinary & Chrb(((Char3 And 60) \ 4) Or (Char2 * 16) And &HFF)
Byte3 = Chrb((((Char3 And 3) * 64) And &HFF) Or (Char4 And 63))
lsGroupBinary = Byte1 & Byte2 & Byte3

lsResult = lsResult & lsGroupBinary
Next

'处理最后剩余的几个字符
if M4 > 0 then
lsGroupBinary = ""
lsGroup64 = Midb(asContents, len2+1, m4) & chrB(65) 'chr(65)=A,转换成值为0
if M4=2 then '补足4位,是为了便于计算
lsGroup64 = lsGroup64 & chrB(65)
end if
Char1 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 1, 1)) - 1
Char2 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 2, 1)) - 1
Char3 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 3, 1)) - 1
Char4 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 4, 1)) - 1
Byte1 = Chrb(((Char2 And 48) \ 16) Or (Char1 * 4) And &HFF)
Byte2 = lsGroupBinary & Chrb(((Char3 And 60) \ 4) Or (Char2 * 16) And &HFF)
Byte3 = Chrb((((Char3 And 3) * 64) And &HFF) Or (Char4 And 63))

if M4=2 then
lsGroupBinary = Byte1
elseif M4=3 then
lsGroupBinary = Byte1 & Byte2
end if

lsResult = lsResult & lsGroupBinary
end if

Base64decode = lsResult

End Function
onkey1999 2004-08-17
  • 打赏
  • 举报
回复
现在都流行源码开放,有什么好保密的,还不一定是原创。
ycted 2004-08-17
  • 打赏
  • 举报
回复
路过.观看.我想没有绝对的吧.
xxrl 2004-08-17
  • 打赏
  • 举报
回复
楼上的都什么东西啊?不知所云
skulldownz 2004-08-17
  • 打赏
  • 举报
回复
反正无论如何..

都能看到客户端的SCRIPT..
nchen123 2004-08-17
  • 打赏
  • 举报
回复
:)
fason 2004-08-17
  • 打赏
  • 举报
回复
通过底层的方法来抓数据包,基本上什么方法都没用。

<script type="text/javascript" src="js.asp"></script>
用Request("http_referer")和SessionID相结合应该可以阻止七八成的人看到代码
DosonWL 2004-08-17
  • 打赏
  • 举报
回复
用这个把页面代码加密:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0032)http://www.ie-zone.com/index.php -->
<HTML>
<!-- #BeginTemplate "/Templates/Js.dwt" -->
<HEAD>
<!-- #BeginEditable "doctitle" -->
<TITLE>加密页面代码生成器 </TITLE>
<!-- #EndEditable -->
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<LINK
href="/fav.ico" rel="shortcut icon">
<STYLE type=text/css>BODY {
MARGIN: 25px 25px 25px
}
#all TD {
FONT-SIZE: 12px; LINE-HEIGHT: 15px; FONT-FAMILY: "Verdana", "Arial","新宋体", "宋体"
}
INPUT {
FONT-SIZE: 12px; LINE-HEIGHT: 15px; FONT-FAMILY: "Verdana", "Arial","新宋体", "宋体"
}
SELECT {
FONT-SIZE: 12px; LINE-HEIGHT: 15px; FONT-FAMILY: "Verdana", "Arial","新宋体", "宋体"
}
P {
FONT-SIZE: 12px; LINE-HEIGHT: 15px; FONT-FAMILY: "Verdana", "Arial","新宋体", "宋体"
}
TEXTAREA {
FONT-SIZE: 12px; LINE-HEIGHT: 15px; FONT-FAMILY: "Verdana", "Arial","新宋体", "宋体"
}

#all A:active {
COLOR: #7d070c
}
#all A:visited {
COLOR: #7d070c
}

#all A:hover {
COLOR: #336699
}
#all A:link {
COLOR: #7d070c
}
</STYLE>
<SCRIPT language=JavaScript>
<!--

function MM_goToURL() { //v3.0
var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function JM_cc(ob){
var obj=MM_findObj(ob); if (obj) {
obj.select();js=obj.createTextRange();js.execCommand("Copy");}
}

function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
//-->
</SCRIPT>
<META content="MSHTML 5.50.4134.600" name=GENERATOR>
</HEAD>
<BODY id=all text=#000000 bgColor=#336699>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TR bgColor=#ffffff>
<TD><IMG src="/images/sq_1.gif" width=11 height="14"></TD>
<TD width="100%"></TD>
<TD><IMG src="/images/sq_2.gif"
width=11 height="14"></TD>
</TR>
</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TR bgColor=#ffffff>
<TD><IMG src="/images/space.gif" width=11 height="1"></TD>
<TD width="100%">
<table width="100%" border="0" cellpadding="8">
<tr>
<td align="center">
<script language="JavaScript">
document.write("<font color=#7d070c style=\"font-size: 14px\">"+document.title+"</font>");
</script>
</td>
</tr>
<tr>
<td bgcolor="#f7f7f7"><!-- #BeginEditable "example" --><font face="Verdana">提示:</font>
把你想加密的文档的源代码拷贝到下面的文本框内,按下生成按钮就可以得到一段加密了的页面代码,把代码复制到新的页面就可以了. [注意:可重复加密啊!]
<script language=JavaScript>
<!--
//////////////////////////////////////////////////////////////////
// Source Code Encrypter v1.0 //
//////////////////////////////////////////////////////////////////
// //
// This JavaScript can be freely used as long as this message //
// stays here in the header of the script. Any modifications //
// and bugs found (and fixed) are appreciated. //
// Script submitted/featured on Dynamicdrive.com //
// Visit http://www.dynamicdrive.com for source code //
// Svetlin Staev, thewebmonster@altavista.com //
//////////////////////////////////////////////////////////////////

var i=0;
var ie=(document.all)?1:0;
var ns=(document.layers)?1:0;

function initStyleElements() /* Styles for Buttons Init */
{
var c = document.pad;
if (ie)
{
//c.text.style.backgroundColor="#DDDDDD";
c.compileIt.style.backgroundColor="#C0C0A8";
c.compileIt.style.cursor="hand";
c.select.style.backgroundColor="#C0C0A8";
c.select.style.cursor="hand";
c.view.style.backgroundColor="#C0C0A8";
c.view.style.cursor="hand";
c.retur.style.backgroundColor="#C0C0A8";
c.retur.style.cursor="hand";
c.clear.style.backgroundColor="#C0C0A8";
c.clear.style.cursor="hand";
}
else return;
}

/* Buttons Enlightment of "Compilation" panel */
function LightOn(what)
{
if (ie) what.style.backgroundColor = '#E0E0D0';
else return;
}
function FocusOn(what)
{
if (ie) what.style.backgroundColor = '#EBEBEB';
else return;
}
function LightOut(what)
{
if (ie) what.style.backgroundColor = '#C0C0A8';
else return;
}
function FocusOff(what)
{
if (ie) what.style.backgroundColor = '#DDDDDD';
else return;
}
/* Buttons Enlightment of "Compilation" panel */

function generate() /* Generation of "Compilation" */
{
code = document.pad.text.value;
if (code)
{
document.pad.text.value='正在生成加密代码,请稍后!';
setTimeout("compile()",1000);
}
else alert('请输入源文件代码')
}
function compile() /* The "Compilation" */
{
document.pad.text.value='';
compilation=escape(code);
document.pad.text.value="<script>\n<!--\ndocument.write(unescape(\""+compilation+"\"));\n//-->\n<\/script>";
i++;
alert("页面被加密了 "+i+" 次!");
}
function selectCode() /* Selecting "Compilation" for Copying */
{
if(document.pad.text.value.length>0)
{
document.pad.text.focus();
document.pad.text.select();
}
else alert('没有可以选择的文本内容!')
}
function preview() /* Preview for the "Compilation" */
{
if(document.pad.text.value.length>0)
{
pr=window.open("","Preview","scrollbars=1,menubar=1,status=1,width=700,height=320,left=50,top=110");
pr.document.write(document.pad.text.value);
}
else alert('没有可以预浏览的文本内容!')
}
function uncompile() /* Decompiling a "Compilation" */
{
if (document.pad.text.value.length>0)
{
source=unescape(document.pad.text.value);
document.pad.text.value=""+source+"";
}
else alert('你需要生成被加密的代码后才能取回源代码!')
}
// -->
</script>
<table cellspacing=0 cellpadding=0 width="100%" border=0>
<tbody>
<tr>
<td width="100%">
<form name=pad method=post align="center">
<textarea style="WIDTH: 100%; BACKGROUND-COLOR: #ebebeb" name=text rows=21 cols=58></textarea>
<br>
<input onMouseOver=LightOn(this) onClick=generate() onMouseOut=LightOut(this) type=button value=加密代码 name=compileIt>
<input onMouseOver=LightOn(this) onClick=selectCode() onMouseOut=LightOut(this) type=button value=全选代码 name=select>
<input onMouseOver=LightOn(this) onClick=preview() onMouseOut=LightOut(this) type=button value=预浏览页面 name=view>
<input onMouseOver=LightOn(this) onClick=uncompile() onMouseOut=LightOut(this) type=button value=原代码 name=retur>
<input onMouseOver=LightOn(this) onMouseOut=LightOut(this) type=reset value=清空 name=clear>
</form>

</td>
</tr>
</tbody>
</table>
<!-- #EndEditable --></td>
</tr>
<tr>
<td><!-- #BeginEditable "code" --><br>
<form name="form1" method="post" action="">
</form>
<!-- #EndEditable --></td>
</tr>
</table>
</TD>
<TD><IMG src="/images/space.gif"
width=11 height="1"></TD>
</TR>
</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TR bgColor=#ffffff>
<TD><IMG src="/images/sq_3.gif" width=11 height="14"></TD>
<TD width="100%"></TD>
<TD><IMG src="/images/sq_4.gif"
width=11 height="14"></TD>
</TR>
</TABLE>
</BODY>
<!-- #EndTemplate -->
</HTML>
加载更多回复(17)

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧