Base64算法的过程
///
/// encode : byte[] to byte[]
///
///
///
public static byte[] urlsafeEncodeBytes(byte[] src)
{
if (src.Length % 3 == 0)
{
return encodeBase64Ex(src);
}
byte[] b = encodeBase64Ex(src);
if (b.Length % 4 == 0)
{
return b;
}
int pad = 4 - b.Length % 4;
byte[] b2 = new byte[b.Length + pad];
Array.Copy(b, 0, b2, 0, b.Length);
b2[b.Length] = (byte)'=';
if (pad > 1)
{
b2[b.Length + 1] = (byte)'=';
}
return b2;
}
///
/// 进行url友好的base64-encode,replace '/' with '_', '+" with '-'
///
/// byte[]
/// byte[]
///
private static byte[] encodeBase64Ex(byte[] src)
{
string srcString = System.Convert.ToBase64String(src);
byte[] b64 = System.Text.Encoding.UTF8.GetBytes(srcString);
for (int i = 0; i < b64.Length; i++)
{
if (b64[i] == '/')
{
b64[i] = System.Convert.ToByte('_');
}
else if (b64[i] == '+')
{
b64[i] = System.Convert.ToByte('-');
}
}
return b64;
}
base64 url友好的编码难道不是用第二个方法 private static byte[] encodeBase64Ex(byte[] src) 就够了吗?
第一个方法 public static byte[] urlsafeEncodeBytes(byte[] src) 是干什么用的呢?
相关阅读:
python 利用requests模拟登陆问题
我在Github 上面上建了一个repositories,怎么才能让他人也有push到这个repositories的权限?
nodejs下用npm安装express出错,试过各种方法,都解决不了,求助!
【iOS】为什么在Category中创建的UIView的点击事件无效
请教wifidirect如何获取peer IP信息
docker 安装mysql数据挂载问题
react native用vs code编写StyleSheet.create出现的提示框
windows安装了git以后就可以运行shell脚本了吗?
php如何定义一个可以接受null的函数
Python爬虫: [urllib2.HTTPError: HTTP Error 403: Forbidden]
PHP如何选择服务器操作系统?
angularjs ng-animate在ng-repeat情况下不起作用问题
MYSQL 多级子查询 简单问题求助
PHP中Sockets与流有什么关系啊!!!!!
请问html之间怎么传递json对象?
php表达式中的 & 和| 分别什么意思啊?
点击后退按钮时,如何让页面不后退
现在的WEB前端开发的最前沿的技术是什么
在Ubuntu下如何用latex编辑生僻字?
iOS使用HTTPS,收集第三方sdk的的HTTPS