base 64 解码

base64 bb = new base64();
string orgStr= Encoding.Default.GetString(bb.GetDecoded("base64编译后的字符"));

UTF8

Subject = Encoding.GetEncoding("utf-8").GetString(Convert.FromBase64String("utf编译后的字符")); 

base64加密

public class base64
{
char[] source;
int length, length2, length3;
int blockCount;
int paddingCount;
public static base64 Decoder = new base64();
public base64()
{ }
private void init(char[] input)
{
int temp = 0;
source = input;
length = input.Length; for (int x = 0; x < 2; x++)
{
if (input[length - x - 1] == '=')
temp++;
}
paddingCount = temp; blockCount = length / 4;
length2 = blockCount * 3;
}
/// <summary>
/// 加密后的字符串解密
/// </summary>
/// <param name="strInput"></param>
/// <returns></returns>
public byte[] GetDecoded(string strInput)
{
//初始化
init(strInput.ToCharArray()); byte[] buffer = new byte[length];
byte[] buffer2 = new byte[length2]; for (int x = 0; x < length; x++)
{
buffer[x] = char2sixbit(source[x]);
} byte b, b1, b2, b3;
byte temp1, temp2, temp3, temp4; for (int x = 0; x < blockCount; x++)
{
temp1 = buffer[x * 4];
temp2 = buffer[x * 4 + 1];
temp3 = buffer[x * 4 + 2];
temp4 = buffer[x * 4 + 3]; b = (byte)(temp1 << 2);
b1 = (byte)((temp2 & 48) >> 4);
b1 += b; b = (byte)((temp2 & 15) << 4);
b2 = (byte)((temp3 & 60) >> 2);
b2 += b; b = (byte)((temp3 & 3) << 6);
b3 = temp4;
b3 += b; buffer2[x * 3] = b1;
buffer2[x * 3 + 1] = b2;
buffer2[x * 3 + 2] = b3;
} length3 = length2 - paddingCount;
byte[] result = new byte[length3]; for (int x = 0; x < length3; x++)
{
result[x] = buffer2[x];
} return result;
} private byte char2sixbit(char c)
{
char[] lookupTable = new char[64]{
'A','B','C','D','E','F','G','H','I','J','K','L','M','N',
'O','P','Q','R','S','T','U','V','W','X','Y', 'Z',
'a','b','c','d','e','f','g','h','i','j','k','l','m','n',
'o','p','q','r','s','t','u','v','w','x','y','z',
'0','1','2','3','4','5','6','7','8','9','+','/'};
if (c == '=')
return 0;
else
{
for (int x = 0; x < 64; x++)
{
if (lookupTable[x] == c)
return (byte)x;
} return 0;
} } /// <summary>
/// Base64解密,采用utf8编码方式解密
/// </summary>
/// <param name="result">待解密的密文</param>
/// <returns>解密后的字符串</returns>
public static string DecodeBase64(string result)
{
return DecodeBase64(Encoding.UTF8, result);
}
/// <summary>
/// Base64解密
/// </summary>
/// <param name="codeName">解密采用的编码方式,注意和加密时采用的方式一致</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;
}
/// <summary>
/// Base64加密
/// </summary>
/// <param name="codeName">加密采用的编码方式</param>
/// <param name="source">待加密的明文</param>
/// <returns></returns>
public static string EncodeBase64(Encoding encode, string source)
{
string decode = "";
byte[] bytes = encode.GetBytes(source);
try
{
decode = Convert.ToBase64String(bytes);
}
catch
{
decode = source;
}
return decode;
} /// <summary>
/// Base64加密,采用utf8编码方式加密
/// </summary>
/// <param name="source">待加密的明文</param>
/// <returns>加密后的字符串</returns>
public static string EncodeBase64(string source)
{
return EncodeBase64(Encoding.UTF8, source);
}
}

C#BASE64 UTF8字符串加密解密的更多相关文章

  1. C# 字符串加密解密函数

    原文:C# 字符串加密解密函数 using System; using System.Text;using System.Security.Cryptography; using System.IO; ...

  2. 简单的JavaScript字符串加密解密

    简单的JavaScript字符串加密解密 <div> <input type="text" id="input" autofocus=&quo ...

  3. java字符串加密解密

    java字符串加密解密 字符串加密解密的方式很多,每一种加密有着相对的解密方法.下面要说的是java中模拟php的pack和unpack的字符串加密解密方法. java模拟php中pack: /** ...

  4. 用C#实现Base64处理,加密解密,编码解码

    using System; using System.Text; namespace Common { /// <summary> /// 实现Base64加密解密 /// 作者:周公 / ...

  5. C# 字符串加密解密方法

    这个是加密的算法的命名空间,使用加密算法前要引用该程序集  System.Security.Cryptography using System;using System.Data;using Syst ...

  6. 在JavaWeb项目中URL中字符串加密解密方案

    URL由来: 一般来说,URL只能使用英文字母.阿拉伯数字和某些标点符号,不能使用其他文字和符号.比如,世界上有英文字母的网址 “http://www.abc.com”,但是没有希腊字母的网址“htt ...

  7. NET实现RSA AES DES 字符串 加密解密以及SHA1 MD5加密

    本文列举了    数据加密算法(Data Encryption Algorithm,DEA) 密码学中的高级加密标准(Advanced EncryptionStandard,AES)RSA公钥加密算法 ...

  8. base64,base32bit加密解密

    import base64 str='admin' str=str.encode('utf-8') #加密 bs64=base64.b64encode(str) #解密 debs64=base64.b ...

  9. 从网上整理的一些delphi字符串加密解密方法

    function Encode(Str: string): string; var //加密 TmpChr: AnsiChar; i, Len: integer; begin Result := St ...

随机推荐

  1. 30个你不可不知的CSS选择器

    30个你不可不知的CSS选择器   一.五大基本选择符 1. *(通配符)*通配符选择器,经常用于css reset(样式重置),清理标签的默认样式,但现在一般不提倡直接使用*了,主要是*会匹配所有标 ...

  2. Oracle入门学习笔记

    参考文献 中文教程     http://wenku.baidu.com/view/b425f404e87101f69e319566.html 经典教程     http://wenku.baidu. ...

  3. php将unicode编码转为utf-8方法

    介绍 在前端开发中,为了让中文在不同的环境下都能很好的显示,一般是将中文转化为unicode格式,即\u4f60,比如:"你好啊"的 unicode编码为"\u4f60\ ...

  4. 存储过程与SQL的结合使用

    --1调用存储过程exec 存储过程名 参数 openrowset方法使用: select * from openrowset('sqlncli', 'server=192.168.247.64;ui ...

  5. Android L 之 RecyclerView 、CardView 、Palette

    转: http://blog.csdn.net/xyz_lmn/article/details/38735117 <Material Design>提到,Android L版本中新增了Re ...

  6. PHP json_encode()函数使用

    <?php $tmp = array(); echo json_encode($tmp); //打印 [] echo "\n"; echo json_encode($tmp, ...

  7. 初学swift笔记字典、数组(四)

    import Foundation //字典 元素顺序是无序的 //1.字典元素是键值对 (key:value) //key 一定是可哈希的 string\int\bool var dic1=[&qu ...

  8. 测试Web服务接口

    1. http://www.iteye.com/topic/142034 2. http://www.iteye.com/topic/1123835 3.http://yongguang423.ite ...

  9. Today See>

    http://wenku.baidu.com/view/b08f3575f46527d3240ce061.html http://wenku.baidu.com/view/a3419558be2348 ...

  10. OTG中的ID脚风波释疑

    1. 概要 OTG设备使用插头中的ID引脚来区分A/B Device,ID接地被称作为A-Device,充当USB Host,A-Device始终为总线提供电力,ID悬空被称作为B-Device,充当 ...