js base64加密与C#后台base64解密
js代码
function encode64(input) {
var output = "";
var base = new Base64();
var output = base.encode(input);
return output;
} function Base64() { // private property
_keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; // public method for encoding
this.encode = function (input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = ;
input = _utf8_encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> ;
enc2 = ((chr1 & ) << ) | (chr2 >> );
enc3 = ((chr2 & ) << ) | (chr3 >> );
enc4 = chr3 & ;
if (isNaN(chr2)) {
enc3 = enc4 = ;
} else if (isNaN(chr3)) {
enc4 = ;
}
output = output +
_keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
_keyStr.charAt(enc3) + _keyStr.charAt(enc4);
}
return output;
} // public method for decoding
this.decode = function (input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = ;
input = input.replace(/[^A-Za-z0-\+\/\=]/g, "");
while (i < input.length) {
enc1 = _keyStr.indexOf(input.charAt(i++));
enc2 = _keyStr.indexOf(input.charAt(i++));
enc3 = _keyStr.indexOf(input.charAt(i++));
enc4 = _keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << ) | (enc2 >> );
chr2 = ((enc2 & ) << ) | (enc3 >> );
chr3 = ((enc3 & ) << ) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != ) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != ) {
output = output + String.fromCharCode(chr3);
}
}
output = _utf8_decode(output);
return output;
} // private method for UTF-8 encoding
_utf8_encode = function (string) {
string = string.replace(/\r\n/g, "\n");
var utftext = "";
for (var n = ; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < ) {
utftext += String.fromCharCode(c);
} else if ((c > ) && (c < )) {
utftext += String.fromCharCode((c >> ) | );
utftext += String.fromCharCode((c & ) | );
} else {
utftext += String.fromCharCode((c >> ) | );
utftext += String.fromCharCode(((c >> ) & ) | );
utftext += String.fromCharCode((c & ) | );
} }
return utftext;
} // private method for UTF-8 decoding
_utf8_decode = function (utftext) {
var string = "";
var i = ;
var c = c1 = c2 = ;
while (i < utftext.length) {
c = utftext.charCodeAt(i);
if (c < ) {
string += String.fromCharCode(c);
i++;
} else if ((c > ) && (c < )) {
c2 = utftext.charCodeAt(i + );
string += String.fromCharCode(((c & ) << ) | (c2 & ));
i += ;
} else {
c2 = utftext.charCodeAt(i + );
c3 = utftext.charCodeAt(i + );
string += String.fromCharCode(((c & ) << ) | ((c2 & ) << ) | (c3 & ));
i += ;
}
}
return string;
}
}
/// <summary>
/// base64解密
/// </summary>
/// <param name="encode">编码,与js一致</param>
/// <param name="result">加密源字符串</param>
/// <returns></returns>
public static string DecodeBase64(Encoding encode, string result)
{
string decode = "";
byte[] bytes = Convert.FromBase64String(result);
try
{
decode = encode.GetString(bytes);
}
catch
{
decode = result;
}
return decode;
}
js base64加密与C#后台base64解密的更多相关文章
- js前台加密,java后台解密实现
参考资料: JS前台加密,java后台解密实现
- 前端JS AES加密 后端PHP AES加解密
<!DOCTYPEhtml> <html> <head> <title>aes demo</title> </head> < ...
- JS URL 使用base64加密与解密
JS编码方式: <script type="text/javascript"> document.write(encodeURI("http://www.w3 ...
- JS URL 使用base64加密与解密和MD5解密
JS编码方式: <script type="text/javascript"> document.write(encodeURI("http://www.w3 ...
- android Base64加密解密
// 加密传入的数据是byte类型的,并非使用decode方法将原始数据转二进制,String类型的数据 使用 str.getBytes()即可 String str = "Hello!&q ...
- Jmeter中实现base64加密
Jmeter已不再提供内置base64加密函数,遇到base64加密需求,需要通过beanshell实现 直接上beanshell代码: import org.apache.commons.net.u ...
- js实现加密(?!)
<script src="yourUrl/md5.min.js"></script> 或者: <script src="http://cdn ...
- js base64加密,后台解密
这是为了解决页面发送post请求,传输密码,在页面的控制台可以看到密码的明文,所以先用base64把要传输的密码转换为非明文,然后在后台解密处理. base64encode.js // base64加 ...
- jquery对中文进行base64加密,后台用java进行base64解密
项目中遇到将中文从前台传到后台过程中,出现乱码,一番尝试之后,均是乱码,然后尝试在js代码中先进行base64加密,然后在Java中再进行解密,完美的解决了乱码问题,步骤如下 一,html页面引入jQ ...
随机推荐
- PCA(Principal Components Analysis)主成分分析
全是图片..新手伤不起.word弄的,结果csdn传不了..以后改. .
- 开心的小明(南阳oj49)(01背包)
开心的小明 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描写叙述 小明今天非常开心.家里购置的新房就要领钥匙了,新房里有一间他自己专用的非常宽敞的房间.更让他高兴的是,妈妈 ...
- extjs 时间范围选择的实现
extjs中 有时须要选择一个日期范围 ,须要自己主动推断,选择的開始日期不能大于结束日期,或结束日期不能小于開始日期,实现的代码例如以下 效果图: watermark/2/text/aHR0cDov ...
- mysql数据库连接工具类C3P0
package com.dl.network_flow.db; import java.sql.Connection; import java.sql.PreparedStatement; impor ...
- hdu2838Cow Sorting(树状数组+逆序数)
题目链接:点击打开链接 题意描写叙述:给定一个长度为100000的数组,每一个元素范围在1~100000,且互不同样,交换当中的随意两个数须要花费的代价为两个数之和. 问怎样交换使数组有序.花费的代价 ...
- SSH Key的生成和使用(for git)
SSH Key的生成和使用 一.总结 1.用git base生成ssh,会生成id_rsa.pub文件,还有一个私钥文件. $ ssh-keygen -t rsa -C “youremailn ...
- (三)Fegin声明式服务调用
上一篇,讲了SpringClound中的消费者采用Ribbon+Rest来实现,这回我们用组件Feign来实现服务的消费者,Fegin中也是默认集成了Ribbon的;和Eureka结合也能实现负载均衡 ...
- KMP算法中求next数组的实质
在串匹配模式中,KMP算法较蛮力法是高效的算法,我觉得其中最重要的一点就是求next数组: 看了很多资料才弄明白求next数组是怎么求的,我发现我的忘性真的比记性大很多,每次看到KMP算法求next数 ...
- APP信息获取接口
https://itunes.apple.com/lookup?id=APPID&callback=2 http://myapp.com/cgi-bin/mapp/mapp_info?type ...
- MyBatis数据持久化(三)增删改查
上篇文章中我们使用mybatis成功建立数据库会话,并从表中查询出相应的数据,本文在此基础上介绍MyBatis另外几种操作,即插入.修改.删除记录. 1.修改User.xml文件,增加几条sql语句: ...