这篇是我之前做项目时用到的,写了个小demo,发在原来的一个博客里。因为博客空间在国外经常被墙,今天把之前写的一些东西搬到这里来。
迅雷,快车旋风链接编码解码C#源代码
在做一个项目时,有要求用到下载工具下载,于是上网找了找,找到了这些链接的加密规则,自己写了几个转换方法
写的有点急,可能不太完善,若您在使用中发现问题,烦请留言给我指出,谢谢!
using System;
using System.Text;
/*
* Author:大宝http://dabao.im,http://dabao2010.blog.51cto.com
* Desc:迅雷,快车,旋风链接编码解码
*/
namespace Base64Url
{
class Program
{
#region 静态常量
/// <summary>迅雷 thunder://</summary>
publicconststring _thunder = "Thunder://";
/// <summary>快车 flashget://</summary>
publicconststring _flashget = "Flashget://";
/// <summary>QQ旋风 qqdl://</summary>
publicconststring _qqdl = "Qqdl://";
#endregion
staticvoid Main(string[] args)
{
string url = "";
url = "thunder://QUFmdHA6Ly82OjZAZnRwLjY2eXMub3JnOjQ1MDgv44CQ6L+F6Zu35LiL6L29d3d3LmR5MTMxLmNvbeOAkVjmiJjorabliY3kvKDvvJrph6HliJrni7xCROS4reiLseWPjOWtlzEyODDpq5jmuIUucm12Ylpa";
//url = "Flashget://W0ZMQVNIR0VUXWh0dHA6Ly9ibG9nLnhpYW9odW9jaGFpLm5ldFtGTEFTSEdFVF0=&xiaohuochai";
//url="Qqdl://aHR0cDovL2Jsb2cueGlhb2h2b2NoYWkubmV0";
string url2 = "http://xiaohuochai.net";
string thunder = "";
string flashget = "";
string qqdl = "";
//编码
thunder = EncodeUrlToBase64(url2, LinkType.Thunder);
flashget = EncodeUrlToBase64(url2, LinkType.Flashget);
qqdl = EncodeUrlToBase64(url2, LinkType.Qqdl);
Console.Write(thunder + "\r\n" + flashget + "\r\n" + qqdl + "\r\n");
//解码
string result = "您输入的地址可能不是迅雷,快车,旋风中的任何一种!";
if (url.StartsWith(_thunder, true, null))//迅雷
result = DecodeUrlFromBase64(url.Remove(0, _thunder.Length), LinkType.Thunder);
if (url.StartsWith(_flashget, true, null))//快车
result = DecodeUrlFromBase64(url.Remove(0, _flashget.Length), LinkType.Flashget);
if (url.StartsWith(_qqdl, true, null))//QQ旋风
result = DecodeUrlFromBase64(url.Remove(0, _qqdl.Length), LinkType.Qqdl);
Console.Write(result);
Console.ReadLine();
}
#region 编码&解码
#region 编码
/// <summary>
/// 编码URL
/// </summary>
/// <param name="url">原生URL</param>
protectedstaticstring EncodeUrlToBase64(string url, LinkType linktype)
{
string enurl = "";
string tempUrl = "";
switch (linktype)
{
case LinkType.Thunder:
tempUrl = "AA" + url + "ZZ";
enurl = _thunder + EnCodeUrl(tempUrl);
break;
case LinkType.Flashget:
tempUrl = "[FLASHGET]" + url + "[FLASHGET]";
enurl = _flashget + EnCodeUrl(tempUrl) + "&xiaohuochai";//&后为用户自定义信息,具体什么用还不清楚
break;
case LinkType.Qqdl:
enurl = _qqdl + EnCodeUrl(url);
break;
default:
break;
}
return enurl;
}
privatestaticstring EnCodeUrl(string tempUrl)
{
byte[] bytes; string enurl;
bytes = Encoding.Default.GetBytes(tempUrl);
enurl = Convert.ToBase64String(bytes);
return enurl;
}
#endregion
#region 解码
/// <summary>
/// 链接解码
/// </summary>
/// <param name="baseurl">链接</param>
protectedstaticstring DecodeUrlFromBase64(string baseurl, LinkType linktype)
{
string deurl = "";
switch (linktype)
{
case LinkType.Thunder:
deurl = DecodeUrl(baseurl);
deurl = deurl.Remove(0, 2);
deurl = deurl.Remove(deurl.Length - 2);
break;
case LinkType.Flashget:
deurl = DecodeUrl(baseurl.Remove(baseurl.LastIndexOf('&')));
deurl = deurl.Remove(0, 10);
deurl = deurl.Remove(deurl.Length - 10);
break;
case LinkType.Qqdl:
deurl = DecodeUrl(baseurl);
break;
default:
break;
}
return deurl;
}
privatestaticstring DecodeUrl(string baseurl)
{
byte[] bytes;
string deurl;
bytes = Convert.FromBase64String(baseurl);
deurl = Encoding.UTF8.GetString(bytes);
return deurl;
}
#endregion
#endregion
}
/// <summary>
/// 链接类型
/// </summary>
enum LinkType
{
/// <summary>迅雷</summary>
Thunder,
/// <summary>快车</summary>
Flashget,
/// <summary>QQ旋风</summary>
Qqdl
}
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。