JavaScript的MD5加密

1.首先要到http://pajhome.org.uk/crypt/md5/下载js文件。

2.在页面文件中添加:

<script type="text/javascript" src="md5.js"></script>

3.使用函数hex_md5()进行加密,例:

frm.pwd.value =hex_md5(frm.pwd.value);

 

使用示例:

Html代码  收藏代码
  1. <html>  
  2. <head>  
  3. <script type="text/javascript" src="md5.js"></script>  
  4. <script>  
  5. function md5(){  
  6.   var hash=hex_md5(document.getElementById("text").value);  
  7.   document.getElementById("result").value=hash;  
  8. }  
  9. function trans(){  
  10.   frm.pwd.value =hex_md5(frm.pwd.value);  
  11.   document.getElementById("result2").value=frm.pwd.value;  
  12. }  
  13. function submit(){  
  14.   //默认的提交处理,自定义的提交前处理方法不要用submit作为函数名  
  15. }  
  16. //onsubmit="pwd.value =hex_md5(pwd.value)"  
  17. </script>  
  18.   
  19. </head>  
  20. <body>  
  21. http://pajhome.org.uk/crypt/md5/<br>  
  22. MD5加密:<br>  
  23. 转换前:<input type="text" id="text" style="width:300" value="hello world"/><br>  
  24. 转换后:<input type="text" id="result" style="width:300"/><br>  
  25. <input type="button" value="test" onclick="md5()"/>  
  26. <br>  
  27. <form name="frm" >  
  28. name:<input type="text" id="name" /><br>  
  29. password:<input type="password" id="pwd"/><br>  
  30. <input type="button" value="submit" onclick="trans()" /><br>  
  31. 加密后的密码:<input type="text" id="result2" style="width:300"/>  
  32. </form>  
  33. </body>  
  34. </html>  

 from: http://hongan.iteye.com/blog/287044

posted @ 2017-12-03 21:36  ec04  阅读(435)  评论(0)    收藏  举报