您好,登錄后才能下訂單哦!
這篇是我之前做項目時用到的,寫了個小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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。