|
编码
public string EncodeBase64(string code_type,string code) { string encode = ""; byte[] bytes = Encoding.GetEncoding(code_type).GetBytes(code); try { encode = Convert.ToBase64String(bytes); } catch { encode = code; } return encode; } 解码 public string DecodeBase64(string code_type,string code) { string decode = ""; byte[] bytes = Convert.FromBase64String(code); try { decode = Encoding.GetEncoding(code_type).GetString(bytes); } catch { decode = code; } return decode; } |
本文介绍了一种使用C#实现Base64编码和解码的方法。通过两个公共函数,可以将任意字符串转换为Base64编码形式,并能从Base64编码还原回原始字符串。此方法适用于需要在网络中安全传输数据的场景。
1182

被折叠的 条评论
为什么被折叠?



