BASE64 编码解码
2015-07-06 11:32
435 查看
/// <summary> /// Base64编码 /// </summary> /// <param name="data"></param> /// <returns></returns> public string base64Encode(string data) { try { byte[] encData_byte = new byte[data.Length]; encData_byte = System.Text.Encoding.UTF8.GetBytes(data); string encodedData = Convert.ToBase64String(encData_byte); return encodedData; } catch (Exception e) { throw new Exception("Error in base64Encode" + e.Message); } }
/// <summary> /// Base64解码 /// </summary> /// <param name="data"></param> /// <returns></returns> public string base64Decode(string data) { try { System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); byte[] todecode_byte = Convert.FromBase64String(data); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); string result = new String(decoded_char); return result; } catch (Exception e) { throw new Exception("Error in base64Decode" + e.Message); } }
相关文章推荐
- sort如何按指定的列排序
- How do I change the schedule for replication between two domain controllers in a site?
- GraphicsMagick和im4java按比例压缩图片
- C#读写txt文件的两种方法介绍
- 企业需求管理面临困境,oBridge顺势诞生!
- tif图片编辑利器
- 解决由于一个软件限制策略的阻止,windows无法运行此程序cmd.reg
- 实现js呼叫流行
- hdu 2883 kebab
- Swift Compiler Error Binary oprator '+' cannot be applied to operands of type 'UInt16' and 'UInt8'
- 使用WinDug查内存泄露
- 初步探索Log4j
- SQL Server游标的使用
- LeetCode Binary Tree Zigzag Level Order Traversal
- 设计模式--装饰模式(Decorator)
- 掼蛋经验总结
- 安卓手机与电脑无线传输文件(利用ftp服务)
- webapp弹层
- java GraphicsMagick入门
- source、sh、bash、./执行脚本的区别