JavaScript 和asp.net配合编码字符串
时间:2022-04-23
本文章向大家介绍JavaScript 和asp.net配合编码字符串,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
.net 的System.Text.ASCIIEncoding 和System.BitConvertor类配合在服务端加密字符串,客户端使用Javascript解密字符串。代码如下:
<script language="javascript">
/*
==========================================================
This function helps protect the email address from the evil spam-bots
that scan web pages for useful data such as (email addresses).
Instead of using the data directly, the encoded value is stored in the
html and decoded when required.
==========================================================
*/
function decode(ServerEncoded)
{
// The ServerEncoded parameter is a string that contains the encoded data.
// Each character in the ServerEncoded parameter has been converted into
// a two digit number (hex / base16). This function converts the
// series of numbers back into the normal form and returns the
// decoded string to the client
// holds the decoded string
var res = "";
// go through and decode the full input server encoded string
for (i=0; i < ServerEncoded.length;)
{
// holds each letter (2 digits)
var letter = "";
letter = ServerEncoded.charAt(i) + ServerEncoded.charAt(i+1)
// build the real decoded value
res += String.fromCharCode(parseInt(letter,16));
i += 2;
}
//return the new decoded string to allow it to be rendered to screen
return res;
}
/*
==========================================================
This function gets a reference to the server encrypted string and
then decrypts this using the decode() function and sets the
txtDecrypted value to the value return by the decode() function
==========================================================
*/
function GetEmailAndDecode() {
//get the table <A class=iAs style="FONT-WEIGHT: normal; FONT-SIZE: 100%; PADDING-BOTTOM: 1px; COLOR: darkgreen; BORDER-BOTTOM: darkgreen 0.07em solid; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" href="#" target=_blank itxtdid="3146774">element</A>
var txtSvrEncr = document.getElementById('txtServerEncrypted');
var txtJSDecr = document.getElementById('txtDecrypted');
txtJSDecr.value = decode(txtSvrEncr.value);
var txtAllTog = document.getElementById('txtAllTogether');
txtAllTog.value = decode(txtAllTog.value);
}
</script>
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
#region Email Encryption
//if javascript is enabled do the encoding
if (Request.Browser.JavaScript)
{
//do the encryption using the raw email
txtServerEncrypted.Text = System.BitConverter.ToString(
System.Text.ASCIIEncoding.ASCII.GetBytes(
(txtRawEmail.Text))).Replace("-", "");
//do the encryption using the raw email
txtAllTogether.Text = System.BitConverter.ToString(
System.Text.ASCIIEncoding.ASCII.GetBytes(
(txtRawEmail.Text))).Replace("-", "");
}
else
{
//couldnt find javascript so just use normal email
txtServerEncrypted.Text = txtRawEmail.Text;
txtAllTogether.Text = txtRawEmail.Text;
}
#endregion
}
}
具体参见:Simple web based obfuscation
- 使用Metrics.NET 构建 ASP.NET MVC 应用程序的性能指标
- 如何设计完善的构建系统,为日常开发提速一倍
- 两年 100 期技术周报后,我收获了这四点
- 如何为技术博客设计一个推荐系统(中):基于 Google 搜索的半自动推荐
- 我是如何为技术博客设计一个推荐系统(上):统计与评分加权
- c#处理空白字符
- 后台优化:使用应用性能管理工具
- Disruptor-NET和内存栅栏
- 我们是如何将 Cordova 应用嵌入到 React Native 中
- ADO.NET的弹性连接控制[ADO.NET idle connection resiliency]
- ASP.Net MVC 5 in Xamarin Studio 5.2
- 自制基于 Snips 和 Snowboy 的智能音箱来保护你的隐私
- 从 React 将从 BSD 改 MIT 许可证,谈如何选择正确的开源许可
- Topshelf 支持Mono 扩展Topshelf.Linux
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- gff文件转换成gtf文件
- R的save,load函数和 .rda文件
- 10行Python代码自动清理电脑内重复文件,解放双手!
- 【一天一大 lee】二叉树的后序遍历 (难度:中等) - Day20200929
- 一日一技:在Golang下如何相对简单地开发爬虫?
- 原创 | 一文读懂正态分布与贝塔分布
- 收款神器!解读聚合收款码背后的原理
- 短视频商城源码,滑动时渐变效果实现
- CICD实战——服务自动测试
- MySQL 案例:left join 与 BUG
- WordPress缩略图出现A TimThumb error has occured解决办法
- 2020-09-30:谈谈内存对齐。
- leetcode树之对称二叉树
- 【网络技术联盟站】网络安全 | 瑞哥带你全方位解读防火墙技术!
- 腾讯云服务器CVM+CentOS,部署LAMP环境快速搭建WordPress博客