{"record":{"id":"36c0cb9b171c0bbf","repo":"RayWangQvQ/BiliBiliToolPro","slug":"unsupported-algorithm-algorithmname","errorCode":null,"errorMessage":"Unsupported algorithm: {algorithmName}","messagePattern":"Unsupported algorithm: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Ray.BiliBiliTool.Agent/BiliBiliAgent/Utils/LiveHeartBeatCrypto.cs","lineNumber":47,"sourceCode":"                    break;\n                case 5:\n                    result = Hash(result, key, \"HMACSHA384\");\n                    break;\n                default:\n                    break;\n            }\n        }\n        return result;\n    }\n\n    private static string Hash(string text, string key, string algorithmName)\n    {\n        HMAC hamc = algorithmName.ToUpperInvariant() switch\n        {\n            \"HMACSHA256\" => new HMACSHA256(Encoding.UTF8.GetBytes(key)),\n            \"HMACSHA1\" => new HMACSHA1(Encoding.UTF8.GetBytes(key)),\n            \"HMACMD5\" => new HMACMD5(Encoding.UTF8.GetBytes(key)),\n            _ => throw new ArgumentException($\"Unsupported algorithm: {algorithmName}\"),\n        };\n\n        using HMAC hmac = hamc;\n        byte[] hashBytes = hamc.ComputeHash(Encoding.UTF8.GetBytes(text));\n        return BitConverter.ToString(hashBytes).Replace(\"-\", \"\").ToLowerInvariant();\n    }\n}\n","sourceCodeStart":29,"sourceCodeEnd":55,"githubUrl":"https://github.com/RayWangQvQ/BiliBiliToolPro/blob/c599b2c0da964e16ea8c454397aa07bb16212628/src/Ray.BiliBiliTool.Agent/BiliBiliAgent/Utils/LiveHeartBeatCrypto.cs#L29-L55","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nstring hash = LiveHeartBeatCrypto.Hash(text, key, \"SHA256\");\n// after\nstring hash = LiveHeartBeatCrypto.Hash(text, key, \"HMACSHA256\");","handlingStrategy":"validation","validationCode":"string[] supported = { \"HMACSHA256\", \"HMACSHA1\", \"HMACMD5\" };\nif (!supported.Contains(algorithmName.ToUpperInvariant().Replace(\"-\", \"\")))\n    throw new ArgumentException($\"Algorithm '{algorithmName}' not supported; use HMACSHA256/HMACSHA1/HMACMD5\");","typeGuard":null,"tryCatchPattern":"try { hash = LiveHeartBeatCrypto.Hash(text, key, algo); }\ncatch (ArgumentException ex) { logger.LogError(ex, \"Unsupported HMAC algorithm: {Algo}\", algo); }","preventionTips":["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."],"tags":["csharp","hmac","invalid-argument","crypto"],"backgroundTag":"invalid-enum-value","analyzedSha":"c599b2c0da964e16ea8c454397aa07bb16212628","analyzedAt":"2026-09-12T09:48:04.090Z","contentChangedAt":"2026-09-12T09:48:04.090Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}