{"record":{"id":"f7a3f8d9aa0302b6","repo":"peass-ng/PEASS-ng","slug":"invalid-character-in-base32hex-string","errorCode":null,"errorMessage":"Invalid character in base32hex string.","messagePattern":"Invalid character in base32hex string\\.","errorType":"exception","errorClass":"System.ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/Info/CloudInfo/GPSInfo.cs","lineNumber":307,"sourceCode":"    {\n        for (int i = 0; i < Alphabet.Length; i++)\n        {\n            CharMap[Alphabet[i]] = i;\n        }\n    }\n\n    public static byte[] Decode(string input)\n    {\n        input = input.ToLowerInvariant();\n        List<byte> bytes = new List<byte>();\n\n        int buffer = 0;\n        int bitsLeft = 0;\n\n        foreach (char c in input)\n        {\n            if (!CharMap.ContainsKey(c))\n                throw new ArgumentException(\"Invalid character in base32hex string.\");\n\n            buffer = (buffer << 5) | CharMap[c];\n            bitsLeft += 5;\n\n            if (bitsLeft >= 8)\n            {\n                bitsLeft -= 8;\n                bytes.Add((byte)((buffer >> bitsLeft) & 0xFF));\n            }\n        }\n\n        return bytes.ToArray();\n    }\n}","sourceCodeStart":289,"sourceCodeEnd":321,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/Info/CloudInfo/GPSInfo.cs#L289-L321","documentation":"Decode parses a base32hex (RFC 4648, extended hex) encoded string using a CharMap lookup table. If any character in the input is not present in CharMap, the method cannot decode it and throws ArgumentException immediately. This guards against silent data corruption from malformed encoded input.","triggerScenarios":"Calling Decode with a string containing characters outside the base32hex alphabet (0-9, A-V): lowercase letters, padding '=' inside the string, whitespace/newlines, or base32-standard (non-hex) alphabet letters like W, X, Y, Z.","commonSituations":"Decoding a secret copied with trailing newline or spaces; decoding a value encoded with standard base32 (RFC 4648 alphabet) instead of base32hex; manual transcription errors in API keys or tokens pasted into code or config.","solutions":["Sanitize the input: trim whitespace/newlines and remove invalid characters (e.g. '-', ' ') before calling Decode","Normalize case with input.ToUpperInvariant() only if CharMap is case-insensitive; otherwise base32hex is uppercase-only","Verify the data source uses base32hex and not standard base32; re-encode the source if needed","Wrap Decode in try/catch for ArgumentException and surface a clear 'invalid encoded token' message to the user"],"exampleFix":"// before\nbyte[] raw = Decode(userToken);\n// after\nstring cleaned = new string(userToken.Where(char.IsLetterOrDigit).ToArray()).ToUpperInvariant();\nbyte[] raw = Decode(cleaned);","handlingStrategy":"validation","validationCode":"static bool IsValidBase32Hex(string s) =>\n    !string.IsNullOrEmpty(s) && s.All(c => (c >= '0' && c <= '9') || (c >= 'A' && c <= 'V'));","typeGuard":"bool IsDecodable(string input) => input != null && input.Trim().Length > 0 && input.All(c => (c >= '0' && c <= '9') || (c >= 'A' && c <= 'V'));","tryCatchPattern":"try { var raw = Decode(input); }\ncatch (ArgumentException ex) { log.Warn($\"Invalid base32hex input: {ex.Message}\"); return null; }","preventionTips":["Trim and strip whitespace/newlines from encoded values before decoding","Normalize input casing consistent with the CharMap","Confirm the encoding is base32hex, not standard base32","Unit-test Decode against each character of the alphabet and known-invalid chars"],"tags":["csharp","encoding","base32","input-validation"],"backgroundTag":"invalid-base32-character","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}