迅雷,快车旋风链接编码解码C#源代码
在做一个项目时,有要求用到下载工具下载,于是上网找了找,找到了这些链接的加密规则,自己写了几个转换方法
写的有点急,可能不太完善,若您在使用中发现问题,烦请留言给我指出,谢谢!
using System; using System.Text; /* * Author:小火柴https://dabao.me * Desc:迅雷,快车,旋风链接编码解码 */ namespace Base64Url { class Program { #region 静态常量 /// <summary>迅雷 thunder://</summary> public const string _thunder = "Thunder://"; /// <summary>快车 flashget://</summary> public const string _flashget = "Flashget://"; /// <summary>QQ旋风 qqdl://</summary> public const string _qqdl = "Qqdl://"; #endregion static void Main(string[] args) { string url = ""; url = "thunder://QUFmdHA6Ly82OjZAZnRwLjY2eXMub3JnOjQ1MDgv44CQ6L+F6Zu35LiL6L29d3d3LmR5MTMxLmNvbeOAkVjmiJjorabliY3kvKDvvJrph5HliJrni7xCROS4reiLseWPjOWtlzEyODDpq5jmuIUucm12Ylpa"; //url = "Flashget://W0ZMQVNIR0VUXWh0dHA6Ly9ibG9nLnhpYW9odW9jaGFpLm5ldFtGTEFTSEdFVF0=&xiaohuochai"; //url="Qqdl://aHR0cDovL2Jsb2cueGlhb2h1b2NoYWkubmV0"; string url2 = "https://dabao.me"; 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> protected static string 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; } private static string 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> protected static string 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; } private static string 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 } }
转换中文 好像有问题
@希特勒:编码问题,你换编码试试