用Javascript实现邮件加密,写了一个类
最近,朋友要给他的客户与客户交流,涉及一些很重要的信息,通过QQ,MSN感觉很不可靠,于是请我写一个加密解密工具,防止信息在中途被截取。
解密工具直接交给客户,而交流信息通过E-mail或QQ。汗,我等小鸟怎么会那种高深的东东,实在是。。。为了朋友,赴刀山,下火海,奋斗了一个晚上,终于写出来了一个。好东西不敢分享,发出来共享给大家,高手见笑了。
原文地址为:http://miaoqiyuan.cn/p/javascript-jiami
因为朋友特别说是很重要的信息,我想到了以前学C的时候有一个把每个字符的编码读取出来加13的一个算法。正巧Javascript中有一个charCodeAt,呵呵,把要加密的内容,依次对出每个字符的字符编码,然后做一些处理,嘎嘎。。。。只要不知道算法,还是很难破解出来的,呵呵。
具体算法还是大家自己看吧,说出来就没有意思了。本文的算法与给朋友的稍微有些差别,毕竟安全第一。下面是运行界面,还是使用了我喜欢的hta文件。代码全是Javascript。


测试地址:
加密:http://www.miaoqiyuan.cn/products/js-jiami.htm
解密:http://www.miaoqiyuan.cn/products/js-jiemi.htm
加密.hta代码(完全可以保存为html,执行效果一样)
< !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>设置加密邮件内容</title> <script type="text/javascript"> function itArt(){ this.html="Hello"; this.css="color:#000;width:640px;text-indent:20px;padding:5px;border:solid 5px #666;margin:5px;background:#CCC;margin-left:auto;margin-right:auto"; this.length=0; } itArt.prototype = { init:function(){ this.length=this.html.length; }, play:function(){ this.init(); this.setPassword(); this.echo(); }, setHtml:function(v){ this.html=v; }, setPassword:function(){ var tmp=""; for(var i=0;i<this .length;i++){ tmp+="$"+this.html.charCodeAt(i); } this.html=tmp; tmp=""; for(var i=0;i<this.html.length;i+=3){ tmp+=" "+this.html.substr(i,3); } this.html=tmp; tmp=""; for(var i=0;i<this.html.length;i++){ tmp+=" "+this.html.charCodeAt(i); } this.html=tmp; }, echo:function(){ var t=document.createElement("div"); t.innerHTML=this.html; if(window.ActiveXObject) t.style.cssText=this.css; else t.setAttribute("style",this.css); //不想用DOM删掉子元素了,反正各浏览器都支持 document.getElementById("x100").innerHTML=""; document.getElementById("x100").appendChild(t); } } function setPassword(t){ if(t!=""){ var demo=new itArt(); demo.setHtml(t); demo.play(); }else{ alert("请输入内容开始加密"); } } window.onload=function(){ setPassword("你好,猜猜我给你的密文是什么? 哈哈,猜不到吧"); } </script> </this></script></head> <body> <textarea style="display:block;color:#000;width:640px;height:280px;text-indent:20px;border:solid 5px #666;margin:5px;background:#FFF;margin-left:auto;margin-right:auto" ondblclick="setPassword(this.value);" title="双击开始加密">你好,猜猜我给你的密文是什么? 哈哈,猜不到吧</textarea> <div id="x100"> </div> </body>
解密.hta代码
< !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>获取加密邮件内容</title> <script type="text/javascript"> function itArt(){ this.html="Hello"; this.css="color:#000;width:640px;text-indent:20px;padding:5px;border:solid 5px #666;margin:5px;background:#CCC;margin-left:auto;margin-right:auto"; this.length=0; } itArt.prototype = { init:function(){ this.length=this.html.length; }, play:function(){ this.init(); this.setPassword(); this.echo(); }, setHtml:function(v){ this.html=v; }, setPassword:function(){ var tmp=this.html.split(" "),tmps=""; for(i=0;i<tmp .length;i++){ tmps+=String.fromCharCode(tmp[i]); } this.html=tmps.replace(" ",""); tmps=""; tmp=this.html.split("$"); for(i=0;i<tmp.length;i++){ if(tmp[i]!=""&&tmp[i]!=0){ tmps+=String.fromCharCode(tmp[i].replace(" ","")); } } this.html=tmps; }, echo:function(){ var t=document.createElement("div"); t.innerHTML=this.html; if(window.ActiveXObject) t.style.cssText=this.css; else t.setAttribute("style",this.css); //不想用DOM删掉子元素了,反正各浏览器都支持 document.getElementById("x100").innerHTML=""; document.getElementById("x100").appendChild(t); } } demo=new itArt(); demo.setHtml(); function getPassword(t){ if(t!=""){ var demo=new itArt(); demo.setHtml(t); demo.play(); }else{ alert("请输入内容开始解密"); } } window.onload=function(){ getPassword("32 36 50 48 32 51 50 48 32 36 50 50 32 57 48 57 32 36 54 53 32 50 57 50 32 36 50 57 32 52 54 56 32 36 50 57 32 52 54 56 32 36 50 53 32 49 48 53 32 36 51 50 32 52 55 51 32 36 50 48 32 51 50 48 32 36 51 48 32 51 52 48 32 36 50 51 32 52 57 52 32 36 50 53 32 57 57 49 32 36 50 54 32 49 53 57 32 36 50 48 32 49 54 48 32 36 50 48 32 48 52 48 32 36 54 53 32 51 49 49 32 36 51 50 32 36 50 49 32 55 48 52 32 36 50 49 32 55 48 52 32 36 54 53 32 50 57 50 32 36 50 57 32 52 54 56 32 36 49 57 32 57 56 49 32 36 50 49 32 48 52 48 32 36 50 49 32 53 52 51"); } </script> </tmp></script></head> <body> <textarea style="display:block;color:#000;width:640px;height:280px;text-indent:20px;border:solid 5px #666;margin:5px;background:#FFF;margin-left:auto;margin-right:auto" ondblclick="getPassword(this.value);" title="双击开始解密">32 36 50 48 32 51 50 48 32 36 50 50 32 57 48 57 32 36 54 53 32 50 57 50 32 36 50 57 32 52 54 56 32 36 50 57 32 52 54 56 32 36 50 53 32 49 48 53 32 36 51 50 32 52 55 51 32 36 50 48 32 51 50 48 32 36 51 48 32 51 52 48 32 36 50 51 32 52 57 52 32 36 50 53 32 57 57 49 32 36 50 54 32 49 53 57 32 36 50 48 32 49 54 48 32 36 50 48 32 48 52 48 32 36 54 53 32 51 49 49 32 36 51 50 32 36 50 49 32 55 48 52 32 36 50 49 32 55 48 52 32 36 54 53 32 50 57 50 32 36 50 57 32 52 54 56 32 36 49 57 32 57 56 49 32 36 50 49 32 48 52 48 32 36 50 49 32 53 52 51</textarea> <div id="x100"> </div> </body>
“好东西不敢分享”??