using System;
using System.Collections.Generic;
using System.Text;
namespace NET.MST.Fourth.Base64
{
class NET.MST.Fourth.Base64
{
static void Main(string[] args)
{
String abc = "abcde";
//生成UTF8字节数组
Byte[] bytes = Encoding.UTF8.GetBytes(abc);
//转换成Base64字符串
String base64 = BytesToBase64(bytes);
Console.WriteLine(base64);
//转换回UTF8字节数组
bytes = Base64ToBytes(base64);
//转换回字符串
Console.WriteLine(Encoding.UTF8.GetString(bytes));
Console.Read();
}
//把8位字节数组转换成Base64字符串
static String BytesToBase64(Byte[] bytes)
{
try
{
return Convert.ToBase64String(bytes);
}
catch
{
return null;
}
}
//把Base64字符串转换成8位字节数组
static Byte[] Base64ToBytes(String base64)
{
try
{
return Convert.FromBase64String(base64);
}
catch
{
return null;
}
}
}
}
using System.Collections.Generic;
using System.Text;
namespace NET.MST.Fourth.Base64
{
class NET.MST.Fourth.Base64
{
static void Main(string[] args)
{
String abc = "abcde";
//生成UTF8字节数组
Byte[] bytes = Encoding.UTF8.GetBytes(abc);
//转换成Base64字符串
String base64 = BytesToBase64(bytes);
Console.WriteLine(base64);
//转换回UTF8字节数组
bytes = Base64ToBytes(base64);
//转换回字符串
Console.WriteLine(Encoding.UTF8.GetString(bytes));
Console.Read();
}
//把8位字节数组转换成Base64字符串
static String BytesToBase64(Byte[] bytes)
{
try
{
return Convert.ToBase64String(bytes);
}
catch
{
return null;
}
}
//把Base64字符串转换成8位字节数组
static Byte[] Base64ToBytes(String base64)
{
try
{
return Convert.FromBase64String(base64);
}
catch
{
return null;
}
}
}
}