{"record":{"id":"456d6d96b51434b1","repo":"nilaoda/N_m3u8DL-RE","slug":"label-must-be-valid-16-byte-hex-or-base64-input-string-part","errorCode":null,"errorMessage":"{label} must be valid 16-byte HEX or Base64. Input string: {part}","messagePattern":"(.+?) must be valid 16-byte HEX or Base64\\. Input string: (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs","lineNumber":245,"sourceCode":"    /// - KEY（hex）<br/>\n    /// - KID:KEY（hex）<br/>\n    /// - Base64KEY<br/>\n    /// - Base64KID:Base64KEY\n    /// </summary>\n    private static string[]? ParseCustomKeys(ArgumentResult result)\n    {\n        const int KeyBytes = 16;\n        const int KeyHexLen = KeyBytes * 2;\n        \n        string ParsePart(string part, string label)\n        {\n            if (SingleHexKeyRegex().IsMatch(part))\n                return part.ToLowerInvariant();\n\n            if (HexUtil.TryParseBase64(part, out var hex) && hex is { Length: KeyHexLen })\n                return hex.ToLowerInvariant();\n\n            throw new ArgumentException($\"{label} must be valid 16-byte HEX or Base64. Input string: {part}\");\n        }\n\n        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);","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/nilaoda/N_m3u8DL-RE/blob/e113dee70c924ee08dae5460624909b04d84cb76/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs#L227-L263","documentation":"When parsing decryption key options, each KEY/KID:KEY part must be either a 32-char hex string (16 bytes) or a Base64 string that decodes to exactly 16 bytes. ParsePart lowercases the normalized hex and throws ArgumentException if the part matches neither form, naming the label (KEY or KID) and echoing the offending input.","triggerScenarios":"Passing a --key value that is a 24-byte/32-byte key, a hex string with odd length or non-hex characters, a Base64 string decoding to a length other than 16, or a raw passphrase.","commonSituations":"Users paste full 32-byte AES-256 keys, include a '0x' prefix, copy a KID+KEY with surrounding whitespace/extra characters, or supply a key from a non-Standard (non-16-byte) DRM scheme.","solutions":["Provide the key as 32 hex characters (16 bytes), e.g. \"d1f2...\" without 0x prefix.","Or provide valid Base64 whose decoded length is exactly 16 bytes.","Strip whitespace, quotes and '0x' prefixes from the pasted value.","For non-16-byte keys, confirm the stream actually uses 128-bit keys; longer keys are unsupported here."],"exampleFix":"// before\n--key \"0xD1F2E3...\" // 0x prefix, wrong length\n// after\n--key \"d1f2e3c4b5a697887766554433221100\" // 32 hex chars","handlingStrategy":"validation","validationCode":"bool ValidKeyPart(string p) =>\n    System.Text.RegularExpressions.Regex.IsMatch(p, \"^[0-9a-fA-F]{32}$\") ||\n    (TryConvert.FromBase64String(p) is var b && b != null && b.Length == 16);","typeGuard":"bool Is16ByteHexOrB64(string s) => s.Length == 32 && s.All(Uri.IsHexCharacter ?? (char c => Uri.IsHexDigit(c))) || TryBase6416(s);","tryCatchPattern":"try { ParseKeyOption(tokens); }\ncatch (ArgumentException ex) { Console.Error.WriteLine(ex.Message); return 1; }","preventionTips":["Always pass keys as 32 hex characters or Base64 decoding to 16 bytes.","Strip '0x' prefixes, quotes and whitespace before passing.","Confirm the stream uses 128-bit keys; longer keys are rejected."],"tags":["decryption","key-parsing","cli"],"backgroundTag":"invalid-argument-value","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"}