android base64 编码 c# base64解码器,C#Base64编码解码

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Cat8637CallCenter

{

public class CBase64

{

/// /// 将字符串使用base64算法加密

///

/// 编码类型(编码名称)

/// * 代码页 名称

/// * 1200 "UTF-16LE"、"utf-16"、"ucs-2"、"unicode"或"ISO-10646-UCS-2"

/// * 1201

///

/// 将字符串使用base64算法加密

///

/// 编码类型(编码名称)

/// * 代码页 名称

/// * 1200 "UTF-16LE"、"utf-16"、"ucs-2"、"unicode"或"ISO-10646-UCS-2"

/// * 1201 "UTF-16BE"或"unicodeFFFE"

/// * 1252 "windows-1252"

/// * 65000 "utf-7"、"csUnicode11UTF7"、"unicode-1-1-utf-7"、"unicode-2-0-utf-7"、"x-unicode-1-1-utf-7"或"x-unicode-2-0-utf-7"

/// * 65001 "utf-8"、"unicode-1-1-utf-8"、"unicode-2-0-utf-8"、"x-unicode-1-1-utf-8"或"x-unicode-2-0-utf-8"

/// * 20127 "us-ascii"、"us"、"ascii"、"ANSI_X3.4-1968"、"ANSI_X3.4-1986"、"cp367"、"csASCII"、"IBM367"、"iso-ir-6"、"ISO646-US"或"ISO_646.irv:1991"

/// * 54936 "GB18030"

///

/// 待加密的字符串

/// 加密后的字符串

public static string EncodeBase64(string code_type, string code)

{

string encode = "";

byte[] bytes = Encoding.GetEncoding(code_type).GetBytes(code); //将一组字符编码为一个字节序列.

try

{

encode = Convert.ToBase64String(bytes); //将8位无符号整数数组的子集转换为其等效的,以64为基的数字编码的字符串形式.

}

catch

{

encode = code;

}

return encode;

}

public static string EncodeBase64(string code)

{

string encode = "";

byte[] bytes = Encoding.Default.GetBytes(code); //将一组字符编码为一个字节序列.

try

{

encode = Convert.ToBase64String(bytes); //将8位无符号整数数组的子集转换为其等效的,以64为基的数字编码的字符串形式.

}

catch

{

encode = code;

}

return encode;

}

///

/// 2013-11-05 新增

/// 将字符串使用base64算法解密

///

/// 编码类型

/// 已用base64算法加密的字符串

/// 解密后的字符串

public static string DecodeBase64(string code_type, string code)

{

string decode = "";

byte[] bytes = Convert.FromBase64String(code); //将2进制编码转换为8位无符号整数数组.

try

{

decode = Encoding.GetEncoding(code_type).GetString(bytes); //将指定字节数组中的一个字节序列解码为一个字符串。

}

catch

{

decode = code;

}

return decode;

}

public static string DecodeBase64(string code)

{

string decode = "";

byte[] bytes = Convert.FromBase64String(code); //将2进制编码转换为8位无符号整数数组.

try

{

decode = Encoding.Default.GetString(bytes); //将指定字节数组中的一个字节序列解码为一个字符串。

}

catch

{

decode = code;

}

return decode;

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值