如何防止页面中的敏感信息被提取
时间:2008-05-04 11:59:00
公布到网页上的Email经常会被一些工具自动提取,一些非法用户就会利用所提取的Email大肆发送垃圾邮件。这些工具大多都是查找链接中“mailto:”后面的信息或是“@”前后的信息来达到提取Email的目的。我在看DotNetNuke(以下简称DNN)的源代码时发现了一个不错的方式来防止这些信息被自动提取。
在DNN中有这么一段函数(Globals.vb中):
Public Function CloakText(ByVal PersonalInfo As String) As String
If Not PersonalInfo Is Nothing Then
Dim sb As New StringBuilder
' convert to ASCII character codes,将字符串转换成ASCII编码字符串形式
sb.Remove(0, sb.Length)
Dim StringLength As Integer = PersonalInfo.Length - 1
For i As Integer = 0 To StringLength
sb.Append(Asc(PersonalInfo.Substring(i, 1)).ToString)
If i < StringLength Then
sb.Append(",")
End If
Next
' build script block
Dim sbScript As New StringBuilder
sbScript.Append(vbCrLf & "<script language=""javascript"">" & vbCrLf)
sbScript.Append("<!-- " & vbCrLf)
'fromCharCode 方法:从一些 Unicode 字符值中返回一个字符串。
sbScript.Append(" document.write(String.fromCharCode(" & sb.ToString & "))" & vbCrLf)
sbScript.Append("// -->" & vbCrLf)
sbScript.Append("</script>" & vbCrLf)
Return sbScript.ToString
Else
Return Null.NullString
End If
End Function
该段代码先将需要加密的信息转换成ASCII编码字符串形式,然后用javascript中的document.write方法写到页面。
我测试了以下效果,还不错。大家也可以试试。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>测试信息加密</title>
</head>
<body>
可以被提取的链接:<a href="mailto:aaa@163.com">aaa@163.com</a><br>
不能被提取的链接:
<script language="javascript">
<!--
document.write(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,120,120,120,64,116,111,109,
46,99,111,109,34,62,120,120,120,64,116,111,109,46,99,111,109,60,47,97,62))
// -->
</script>
</body>
</html>
如果大家有兴趣,还可以用更加复杂的方法来进行加密,一句话:再也不能让人轻易获取信息了!
标签:email,加密,函数,js
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SQL Server中修改“用户自定义表类型”问题的分析与方法
2024-01-24 01:13:58
![](https://img.aspxhome.com/file/2023/9/108529_0s.png)
python 数字类型和字符串类型的相互转换实例
2021-08-02 08:11:36
python中的正则表达式,贪婪匹配与非贪婪匹配方式
2023-04-04 18:37:36
Python的Flask框架中使用Flask-SQLAlchemy管理数据库的教程
2024-01-21 22:23:32
![](https://img.aspxhome.com/file/2023/6/86186_0s.png)
超常用的PHP正则表达式收集整理
2024-05-03 15:35:57
多阶段构建优化Go 程序Docker镜像
2024-02-20 13:57:40
![](https://img.aspxhome.com/file/2023/4/105824_0s.png)
Python3+cgroupspy安装使用简介
2022-11-13 15:11:21
![](https://img.aspxhome.com/file/2023/2/121152_0s.png)
Python爬虫获取页面所有URL链接过程详解
2022-01-31 10:48:46
Python+Turtle实现绘制可爱的小仓鼠
2022-09-16 20:52:28
![](https://img.aspxhome.com/file/2023/3/87643_0s.png)
Go语言中defer语句的用法
2023-07-07 11:04:17
![](https://img.aspxhome.com/file/2023/3/92023_0s.png)
基于OpenCV目标跟踪实现人员计数器
2022-11-17 15:04:03
![](https://img.aspxhome.com/file/2023/5/103715_0s.png)
asp 去除最后一个逗号为空字符串的代码
2010-06-09 19:18:00
Python3.9新特性详解
2023-03-26 21:56:16
![](https://img.aspxhome.com/file/2023/6/79426_0s.png)
Python使用Pycrypto库进行RSA加密的方法详解
2021-02-28 02:05:33
解读tf.keras.layers模块中的函数
2023-04-02 04:26:29
Python的Asyncore异步Socket模块及实现端口转发的例子
2023-04-23 13:24:38
Python开发常用的一些开源Package分享
2022-12-10 22:00:11
python图像和办公文档处理总结
2021-03-08 19:24:02
![](https://img.aspxhome.com/file/2023/5/72875_0s.png)
python sleep和wait对比总结
2023-04-30 18:26:04
Python模拟登录网易云音乐并自动签到
2023-05-28 03:10:05
![](https://img.aspxhome.com/file/2023/9/80769_0s.png)