zoukankan      html  css  js  c++  java
  • Code:Base64 编码/解码

    ylbtech-Code:Base64 编码/解码
    1. C#返回顶部
    1、编码
    byte[] inArray = new byte[msgTxt.Length];
    int x;
    for(x=0; x < msgTxt.Length; x++) {
         inArray[x] = (byte)charArray[x];
    }
    string encodedString = Convert.ToBase64String(inArray,0,inArray.Length,Base64FormattingOptions.None);
    2、解码
    byte[] outArray = Convert.FromBase64String(respMsg);
    char[] outCharArray =new char[outArray.Length];
    for (x = 0; x < outArray.Length; x++)
    {
         outCharArray[x] = (char)outArray[x];
    }
    string decodedString = new string(outCharArray);
    3、
    4、
    2. JS返回顶部
    ·base64编码
    ·base64解码
    function base64_decode(data) {
      var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
      var o1,
        o2,
        o3,
        h1,
        h2,
        h3,
        h4,
        bits,
        i = 0,
        ac = 0,
        dec = "",
        tmp_arr = [];
      if (!data) {
        return data;
      }
      data += "";
      do {
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));
        bits = (h1 << 18) | (h2 << 12) | (h3 << 6) | h4;
        o1 = (bits >> 16) & 0xff;
        o2 = (bits >> 8) & 0xff;
        o3 = bits & 0xff;
        if (h3 == 64) {
          tmp_arr[ac++] = String.fromCharCode(o1);
        } else if (h4 == 64) {
          tmp_arr[ac++] = String.fromCharCode(o1, o2);
        } else {
          tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
        }
      } while (i < data.length);
      dec = tmp_arr.join("");
      dec = utf8_decode(dec);
      return dec;
    }
    ·
    3.返回顶部
     
    4.返回顶部
     
    5.返回顶部
     
     
    6.返回顶部
     
    warn 作者:ylbtech
    出处:http://ylbtech.cnblogs.com/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    开源协议介绍
    Guice vs Dependency Injection By Hand
    Eclipse与MyEclipse的联系和区别
    Java Basic
    解决Windows Vista 英文版中文软件乱码
    [转]Java B/S开发模式漫谈
    什么是Groovy
    JBoss, Geronimo, Tomcat
    一个让你迅速理解Javabean的实例
    keepalive 原理讲解 salami
  • 原文地址:https://www.cnblogs.com/storebook/p/9188096.html
Copyright © 2011-2022 走看看