From 9485d9b00f500182ae06b645d89530acb6945c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=87=E7=85=8C?= Date: Sun, 1 Sep 2019 23:34:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D163key=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NLyric/NLyric.csproj | 6 +++--- NLyric/The163KeyHelper.cs | 20 +++++--------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/NLyric/NLyric.csproj b/NLyric/NLyric.csproj index 570131c..95bd78c 100644 --- a/NLyric/NLyric.csproj +++ b/NLyric/NLyric.csproj @@ -1,11 +1,11 @@ - + NLyric NLyric NLyric Copyright © 2019 Wwh - 2.2.5.2 - 2.2.5.2 + 2.2.5.3 + 2.2.5.3 ..\bin\$(Configuration) Exe netcoreapp2.1;net472 diff --git a/NLyric/The163KeyHelper.cs b/NLyric/The163KeyHelper.cs index 6fd4f93..864c255 100644 --- a/NLyric/The163KeyHelper.cs +++ b/NLyric/The163KeyHelper.cs @@ -2,11 +2,11 @@ using System.IO; using System.Security.Cryptography; using System.Text; +using Newtonsoft.Json.Linq; namespace NLyric { /// - /// 通过163Key直接获取歌曲ID, - /// 代码来自我原来的项目: https://github.com/wwh1004/netease-cloudmusic-lyrics-downloader + /// 通过163Key直接获取歌曲ID /// internal static class The163KeyHelper { private static readonly byte[] _163Start = Encoding.UTF8.GetBytes("163 key(Don't modify):"); @@ -71,19 +71,9 @@ private static byte[] Get163Key(string filePath, bool isMp3) { private static int GetMusicId(byte[] byt163Key) { byt163Key = Convert.FromBase64String(Encoding.UTF8.GetString(byt163Key)); - byt163Key = _aes.CreateDecryptor().TransformFinalBlock(byt163Key, 0, byt163Key.Length); - return int.Parse(Encoding.UTF8.GetString(byt163Key, 17, GetIndex(byt163Key, 0x2C, 17) - 17)); - } - - private static int GetIndex(byte[] src, byte dest, int startIndex) { - return GetIndex(src, dest, startIndex, src.Length - 1); - } - - private static int GetIndex(byte[] src, byte dest, int startIndex, int endIndex) { - for (int i = startIndex; i < endIndex + 1; i++) - if (src[i] == dest) - return i; - return -1; + using (ICryptoTransform cryptoTransform = _aes.CreateDecryptor()) + byt163Key = cryptoTransform.TransformFinalBlock(byt163Key, 0, byt163Key.Length); + return (int)JObject.Parse(Encoding.UTF8.GetString(byt163Key).Substring(6))["musicId"]; } private static int GetIndex(byte[] src, byte[] dest, int startIndex) {