js判断是不是js base64加密密

关于JS base64 图像显示问题
[问题点数:30分]
关于JS base64 图像显示问题
[问题点数:30分]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2016年2月 总版技术专家分月排行榜第二2014年2月 总版技术专家分月排行榜第二2013年4月 总版技术专家分月排行榜第二
2016年8月优秀小版主2016年7月优秀小版主优秀小版主2015年7月优秀小版主2015年9月优秀小版主2015年5月优秀小版主2014年11月论坛优秀版主
2016年2月 总版技术专家分月排行榜第二2014年2月 总版技术专家分月排行榜第二2013年4月 总版技术专家分月排行榜第二
2016年8月优秀小版主2016年7月优秀小版主优秀小版主2015年7月优秀小版主2015年9月优秀小版主2015年5月优秀小版主2014年11月论坛优秀版主
2016年2月 总版技术专家分月排行榜第二2014年2月 总版技术专家分月排行榜第二2013年4月 总版技术专家分月排行榜第二
2016年8月优秀小版主2016年7月优秀小版主优秀小版主2015年7月优秀小版主2015年9月优秀小版主2015年5月优秀小版主2014年11月论坛优秀版主
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。JS实现的base64加密解密完整实例
作者:fengzheng0306
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了JS实现的base64加密解密,以完整实例形式分析了JavaScript基于base64编码实现加密与解密的具体步骤与相关技巧,并附带了相关的加密解密在线工具地址供大家参考,需要的朋友可以参考下
本文实例讲述了JS实现的base64加密解密。分享给大家供大家参考,具体如下:
完整的代码:
&TITLE&Base64&/TITLE&
&script language=javascript&
var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
var base64DecodeChars = new Array(
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
  52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
  -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
  -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
&TITLE&Base64&/TITLE&
&script language=JavaScript&
var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
var base64DecodeChars = new Array(
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
  52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
  -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
  -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
function base64encode(str) {
  var out, i,
  var c1, c2, c3;
  len = str.
  i = 0;
  out = "";
  while(i & len) {
c1 = str.charCodeAt(i++) & 0
if(i == len)
   out += base64EncodeChars.charAt(c1 && 2);
   out += base64EncodeChars.charAt((c1 & 0x3) && 4);
   out += "==";
c2 = str.charCodeAt(i++);
if(i == len)
   out += base64EncodeChars.charAt(c1 && 2);
   out += base64EncodeChars.charAt(((c1 & 0x3)&& 4) | ((c2 & 0xF0) && 4));
   out += base64EncodeChars.charAt((c2 & 0xF) && 2);
   out += "=";
c3 = str.charCodeAt(i++);
out += base64EncodeChars.charAt(c1 && 2);
out += base64EncodeChars.charAt(((c1 & 0x3)&& 4) | ((c2 & 0xF0) && 4));
out += base64EncodeChars.charAt(((c2 & 0xF) && 2) | ((c3 & 0xC0) &&6));
out += base64EncodeChars.charAt(c3 & 0x3F);
function base64decode(str) {
  var c1, c2, c3, c4;
  var i, len,
  len = str.
  i = 0;
  out = "";
  while(i & len) {
   c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
} while(i & len && c1 == -1);
if(c1 == -1)
   c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
} while(i & len && c2 == -1);
if(c2 == -1)
out += String.fromCharCode((c1 && 2) | ((c2 & 0x30) && 4));
   c3 = str.charCodeAt(i++) & 0
   if(c3 == 61)
   c3 = base64DecodeChars[c3];
} while(i & len && c3 == -1);
if(c3 == -1)
out += String.fromCharCode(((c2 & 0XF) && 4) | ((c3 & 0x3C) && 2));
   c4 = str.charCodeAt(i++) & 0
   if(c4 == 61)
   c4 = base64DecodeChars[c4];
} while(i & len && c4 == -1);
if(c4 == -1)
out += String.fromCharCode(((c3 & 0x03) && 6) | c4);
function utf16to8(str) {
  var out, i, len,
  out = "";
  len = str.
  for(i = 0; i & i++) {
c = str.charCodeAt(i);
if ((c &= 0x0001) && (c &= 0x007F)) {
   out += str.charAt(i);
} else if (c & 0x07FF) {
   out += String.fromCharCode(0xE0 | ((c && 12) & 0x0F));
   out += String.fromCharCode(0x80 | ((c && 6) & 0x3F));
   out += String.fromCharCode(0x80 | ((c && 0) & 0x3F));
   out += String.fromCharCode(0xC0 | ((c && 6) & 0x1F));
   out += String.fromCharCode(0x80 | ((c && 0) & 0x3F));
function utf8to16(str) {
  var out, i, len,
  var char2, char3;
  out = "";
  len = str.
  i = 0;
  while(i & len) {
c = str.charCodeAt(i++);
switch(c && 4)
  case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
   // 0xxxxxxx
   out += str.charAt(i-1);
  case 12: case 13:
   // 110x xxxx  10xx xxxx
   char2 = str.charCodeAt(i++);
   out += String.fromCharCode(((c & 0x1F) && 6) | (char2 & 0x3F));
  case 14:
   // 1110 xxxx 10xx xxxx 10xx xxxx
   char2 = str.charCodeAt(i++);
   char3 = str.charCodeAt(i++);
   out += String.fromCharCode(((c & 0x0F) && 12) |
    ((char2 & 0x3F) && 6) |
    ((char3 & 0x3F) && 0));
function doit() {
  var f = document.f
  f.output.value = base64encode(utf16to8(f.source.value))
  f.decode.value = utf8to16(base64decode(f.output.value))
&H1&Base64&/H1&
&FORM NAME="f"&
&TEXTAREA NAME="source" ROWS=4 COLS=60 WRAP="soft"&&/TEXTAREA&&BR&&BR&
Base64 encode&BR&
&TEXTAREA NAME="output" ROWS=4 COLS=60 WRAP="soft"&&/TEXTAREA&&BR&&BR&
Base64 decode&BR&
&TEXTAREA NAME="decode" ROWS=4 COLS=60 WRAP="soft"&&/TEXTAREA&&BR&&BR&
&INPUT TYPE=BUTTON VALUE="转换" ONCLICK="doit()"&
关于base64加密解密还可参看本站在线工具:
更多加密解密内容还可参考:
更多关于JavaScript相关内容可查看本站专题:《》、《》、《》、《》、《》、《》、《》及《》
希望本文所述对大家JavaScript程序设计有所帮助。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具js-base64 安全与加密 - 开源中国社区
当前访客身份:游客 [
当前位置:
标签代码列表(0)
当前标签下
暂无代码!
开源从代码分享开始<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&javascript实现base64_encode加密,解密的方法
程序传参的过程中对参数的处理常见的有
等等这些函数,但在实际操作中作者发现这些函数处理起来总是会出些问题,最常见的urlencode在网页一连串的跳转过程中传参对&这个符号总是处理的有问题。经试验,作者发现还是使用base64_encode加密然后传参来的靠谱。
在php中对字符串进行base64_encode加密处理很容易,而且有相应的base64_decode函数进行解密,在js中却没有响应的处理方法,下面就和大家分享一个在js中实现php语言中的base64_encode base64_decode的方法。
function base64encode(str){
var out,i,len,base64EncodeChars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
var c1,c2,c3;
while(i&len){
c1=str.charCodeAt(i++)&0
if(i==len){
out+=base64EncodeChars.charAt(c1&&2);
out+=base64EncodeChars.charAt((c1&0x3)&&4);
out+="==";
c2=str.charCodeAt(i++);
if(i==len){
out+=base64EncodeChars.charAt(c1&&2);
out+=base64EncodeChars.charAt(((c1&0x3)&&4)|((c2&0xF0)&&4));
out+=base64EncodeChars.charAt((c2&0xF)&&2);
c3=str.charCodeAt(i++);
out+=base64EncodeChars.charAt(c1&&2);
out+=base64EncodeChars.charAt(((c1&0x3)&&4)|((c2&0xF0)&&4));
out+=base64EncodeChars.charAt(((c2&0xF)&&2)|((c3&0xC0)&&6));
out+=base64EncodeChars.charAt(c3&0x3F);
function base64decode(str){
var c1,c2,c3,c4,base64DecodeChars=new Array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1);
var i,len,
while(i&len){
c1=base64DecodeChars[str.charCodeAt(i++)&0xff];
}while(i&len&&c1==-1);
if(c1==-1)
c2=base64DecodeChars[str.charCodeAt(i++)&0xff];
}while(i&len&&c2==-1);
if(c2==-1)
out+=String.fromCharCode((c1&&2)|((c2&0x30)&&4));
c3=str.charCodeAt(i++)&0
if(c3==61)
c3=base64DecodeChars[c3];
}while(i&len&&c3==-1);
if(c3==-1)
out+=String.fromCharCode(((c2&0XF)&&4)|((c3&0x3C)&&2));
c4=str.charCodeAt(i++)&0
if(c4==61)
c4=base64DecodeChars[c4];
}while(i&len&&c4==-1);
if(c4==-1)
out+=String.fromCharCode(((c3&0x03)&&6)|c4);
function utf16to8(str){
var out,i,len,c;
for (i=0;i&i++){
c=str.charCodeAt(i);
if((c&=0x0001)&&(c&=0x007F)){
out+=str.charAt(i);
} else if(c&0x07FF){
out+=String.fromCharCode(0xE0|((c&&12)&0x0F));
out+=String.fromCharCode(0x80|((c&&6)&0x3F));
out+=String.fromCharCode(0x80|((c&&0)&0x3F));
out+=String.fromCharCode(0xC0|((c&&6)&0x1F));
out+=String.fromCharCode(0x80|((c&&0)&0x3F));
function utf8to16(str){
var out,i,len,c;
var char2,char3;
while(i&len){
c=str.charCodeAt(i++);
switch (c&&4){
// 0xxxxxxx
out+=str.charAt(i-1);
// 110x xxxx
char2=str.charCodeAt(i++);
out+=String.fromCharCode(((c&0x1F)&&6)|(char2&0x3F));
// 1110 xxxx
char2=str.charCodeAt(i++);
char3=str.charCodeAt(i++);
out+=String.fromCharCode(((c&0x0F)&&12)|((char2&0x3F)&&6)|((char3&0x3F)&&0));
代码摘抄自网上,但做了些改进,网上流传的一些代码声明了两个比较大的全局变量,相对起来来说对性能有一些影响。
代码实例参照:您可能感兴趣的文章转载请注明出处:本文永久地址:文章来源:-わ千与千寻上一篇:下一篇:热门文章随机文章

我要回帖

更多关于 js base64加密php解密 的文章

 

随机推荐