RayWangQvQ/BiliBiliToolPro · error · ArgumentException
Unsupported algorithm
Error message
Unsupported algorithm: {algorithmName} What it means
LiveHeartBeatCrypto.Hash builds an HMAC instance from an algorithm name and throws ArgumentException when the name does not match any of the supported cases (HMACSHA256, HMACSHA1, HMACMD5). The library only supports these three algorithms for live heartbeat signing; anything else is rejected up front.
Solutions
- Use one of the exact supported names: 'HMACSHA256', 'HMACSHA1', or 'HMACMD5' (case-insensitive).
- If the desired algorithm is 'SHA256', change it to 'HMACSHA256' — plain SHA-256 is not HMAC and is not supported.
- If a remote/config source supplies the name, normalize it (strip hyphens) before calling, or map known aliases to supported names.
- If a new algorithm is genuinely required, add a new case to the switch expression in LiveHeartBeatCrypto.cs.
Example fix
// before string hash = LiveHeartBeatCrypto.Hash(text, key, "SHA256"); // after string hash = LiveHeartBeatCrypto.Hash(text, key, "HMACSHA256");
Defensive patterns
Strategy: validation
Validate before calling
string[] supported = { "HMACSHA256", "HMACSHA1", "HMACMD5" };
if (!supported.Contains(algorithmName.ToUpperInvariant().Replace("-", "")))
throw new ArgumentException($"Algorithm '{algorithmName}' not supported; use HMACSHA256/HMACSHA1/HMACMD5"); Try / catch
try { hash = LiveHeartBeatCrypto.Hash(text, key, algo); }
catch (ArgumentException ex) { logger.LogError(ex, "Unsupported HMAC algorithm: {Algo}", algo); } Prevention
- Only pass algorithm names from a fixed whitelist, never free-form config or remote data.
- Normalize names (upper-case, strip hyphens) before calling.
- Add a unit test covering each supported algorithm name.
When it happens
Trigger: Calling Hash (directly or via the live heartbeat flow via Sypder) with an algorithmName string that upper-cased is not one of HMACSHA256/HMACSHA1/HMACMD5, e.g. 'SHA256', 'HMAC-SHA256', or an empty string.
Common situations: Misreading the API and passing 'SHA256' instead of 'HMACSHA256'; passing an algorithm name parsed from config or from a remote payload that uses hyphenated or lowercase-with-dash naming; a Bili API protocol change introducing an algorithm this version does not know.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Cookie字符串格式异常,内部无等号
- Cookie字符串异常,无[ ]项
- [ ]= 不能转换为long型,请确认配置的是正确的Cookie值
- 请正确配置Cookie后再运行,配置方式见
- 登录失败,请检查Cookie
AI-assisted analysis of RayWangQvQ/BiliBiliToolPro@c599b2c0da (2026-09-12).
Data as JSON: /api/errors/36c0cb9b171c0bbf.
Report an issue: GitHub.
Appendix: source
Thrown at src/Ray.BiliBiliTool.Agent/BiliBiliAgent/Utils/LiveHeartBeatCrypto.cs:47
break;
case 5:
result = Hash(result, key, "HMACSHA384");
break;
default:
break;
}
}
return result;
}
private static string Hash(string text, string key, string algorithmName)
{
HMAC hamc = algorithmName.ToUpperInvariant() switch
{
"HMACSHA256" => new HMACSHA256(Encoding.UTF8.GetBytes(key)),
"HMACSHA1" => new HMACSHA1(Encoding.UTF8.GetBytes(key)),
"HMACMD5" => new HMACMD5(Encoding.UTF8.GetBytes(key)),
_ => throw new ArgumentException($"Unsupported algorithm: {algorithmName}"),
};
using HMAC hmac = hamc;
byte[] hashBytes = hamc.ComputeHash(Encoding.UTF8.GetBytes(text));
return BitConverter.ToString(hashBytes).Replace("-", "").ToLowerInvariant();
}
}
View on GitHub (pinned to c599b2c0da)