{"record":{"id":"146e05f6f44875ba","repo":"nilaoda/N_m3u8DL-RE","slug":"input-must-be-key-or-kid-key-format","errorCode":null,"errorMessage":"Input must be KEY or KID:KEY format.","messagePattern":"Input must be KEY or KID:KEY format\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs","lineNumber":266,"sourceCode":"        var keys = new List<string>();\n        var inputs = result.Tokens.Select(t => t.Value).ToList();\n\n        try\n        {\n            foreach (var input in inputs)\n            {\n                // 已匹配标准格式的，直接添加\n                if (PairKeyRegex().IsMatch(input) || IdHexKeyRegex().IsMatch(input) || SingleHexKeyRegex().IsMatch(input))\n                {\n                    keys.Add(input);\n                    continue;\n                }\n\n                // 拆分KID:KEY\n                var parts = input.Split(':', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);\n\n                if (parts.Length is < 1 or > 2)\n                    throw new ArgumentException(\"Input must be KEY or KID:KEY format.\");\n\n                if (parts.Length == 1)\n                {\n                    var key = ParsePart(parts[0], \"KEY\");\n                    keys.Add(key);\n                }\n                else // KID:KEY\n                {\n                    var kid = ParsePart(parts[0], \"KID\");\n                    var key = ParsePart(parts[1], \"KEY\");\n                    keys.Add($\"{kid}:{key}\");\n                }\n            }\n\n            return [.. keys];\n        }\n        catch (Exception ex)\n        {","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/nilaoda/N_m3u8DL-RE/blob/e113dee70c924ee08dae5460624909b04d84cb76/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs#L248-L284","documentation":"The --key option accepts either a bare KEY or a KID:KEY pair. After splitting on ':' and trimming/removing empties, anything with more than two parts (or, unreachable here, fewer than one) is rejected with ArgumentException(\"Input must be KEY or KID:KEY format.\").","triggerScenarios":"Passing a value with two or more colons such as \"kid:key:extra\", or a full URI-form key like \"urn:uuid:kid:key\"; only \"KEY\" or \"KID:KEY\" are accepted.","commonSituations":"Users paste a full license/URI string containing multiple colons, include a scheme prefix (e.g. 'key:'), or combine kid:key:iv triples from other tools that use a different delimiter.","solutions":["Reduce the input to exactly \"KID:KEY\" (two parts) or just \"KEY\".","Strip scheme prefixes and any trailing ':IV' or ':extra' components.","If the tool supports multiple keys, pass separate --key options instead of colon-chaining.","Verify KID and KEY are each valid 16-byte HEX/Base64 (see the KEY-format error)."],"exampleFix":"// before\n--key \"kid:key:iv\"\n// after\n--key \"kid:key\"","handlingStrategy":"validation","validationCode":"var parts = input.Split(':', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);\nif (parts.Length is < 1 or > 2) throw new FormatException(\"Use KEY or KID:KEY\");","typeGuard":"bool IsKeyOrKidKey(string s) { var p = s.Split(':'); return p.Length == 1 || p.Length == 2; }","tryCatchPattern":"try { ParseKeys(input); }\ncatch (ArgumentException ex) { Console.Error.WriteLine($\"{ex.Message} Got: '{input}'\"); }","preventionTips":["Never pass values with more than one colon to --key.","Strip scheme prefixes and IV components from copied license strings.","Pass multiple keys as repeated --key options instead of chaining."],"tags":["decryption","key-parsing","cli"],"backgroundTag":"invalid-argument-format","analyzedSha":"e113dee70c924ee08dae5460624909b04d84cb76","analyzedAt":"2026-09-13T02:43:21.078Z","contentChangedAt":"2026-09-13T02:43:21.078Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}