Skip to content

Commit

Permalink
修复163key获取错误
Browse files Browse the repository at this point in the history
  • Loading branch information
wwh1004 committed Sep 1, 2019
1 parent 9dd3a64 commit 9485d9b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
6 changes: 3 additions & 3 deletions NLyric/NLyric.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>NLyric</AssemblyName>
<Title>NLyric</Title>
<Product>NLyric</Product>
<Copyright>Copyright © 2019 Wwh</Copyright>
<AssemblyVersion>2.2.5.2</AssemblyVersion>
<FileVersion>2.2.5.2</FileVersion>
<AssemblyVersion>2.2.5.3</AssemblyVersion>
<FileVersion>2.2.5.3</FileVersion>
<OutputPath>..\bin\$(Configuration)</OutputPath>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.1;net472</TargetFrameworks>
Expand Down
20 changes: 5 additions & 15 deletions NLyric/The163KeyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using System.IO;
using System.Security.Cryptography;
using System.Text;
using Newtonsoft.Json.Linq;

namespace NLyric {
/// <summary>
/// 通过163Key直接获取歌曲ID,
/// 代码来自我原来的项目: https://github.com/wwh1004/netease-cloudmusic-lyrics-downloader
/// 通过163Key直接获取歌曲ID
/// </summary>
internal static class The163KeyHelper {
private static readonly byte[] _163Start = Encoding.UTF8.GetBytes("163 key(Don't modify):");
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9485d9b

Please sign in to comment.