peass-ng/PEASS-ng · error · System.ArgumentException
Invalid character in base32hex string.
Error message
Invalid character in base32hex string.
What it means
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.
Source
Thrown at winPEAS/winPEASexe/winPEAS/Info/CloudInfo/GPSInfo.cs:307
{
for (int i = 0; i < Alphabet.Length; i++)
{
CharMap[Alphabet[i]] = i;
}
}
public static byte[] Decode(string input)
{
input = input.ToLowerInvariant();
List<byte> bytes = new List<byte>();
int buffer = 0;
int bitsLeft = 0;
foreach (char c in input)
{
if (!CharMap.ContainsKey(c))
throw new ArgumentException("Invalid character in base32hex string.");
buffer = (buffer << 5) | CharMap[c];
bitsLeft += 5;
if (bitsLeft >= 8)
{
bitsLeft -= 8;
bytes.Add((byte)((buffer >> bitsLeft) & 0xFF));
}
}
return bytes.ToArray();
}
}View on GitHub (pinned to 53fb989abc)
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
Example fix
// before byte[] raw = Decode(userToken); // after string cleaned = new string(userToken.Where(char.IsLetterOrDigit).ToArray()).ToUpperInvariant(); byte[] raw = Decode(cleaned);
Defensive patterns
Strategy: validation
Validate before calling
static bool IsValidBase32Hex(string s) =>
!string.IsNullOrEmpty(s) && s.All(c => (c >= '0' && c <= '9') || (c >= 'A' && c <= 'V')); Type guard
bool IsDecodable(string input) => input != null && input.Trim().Length > 0 && input.All(c => (c >= '0' && c <= '9') || (c >= 'A' && c <= 'V'));
Try / catch
try { var raw = Decode(input); }
catch (ArgumentException ex) { log.Warn($"Invalid base32hex input: {ex.Message}"); return null; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- drivePath
- driveName
- malformed BMPString encoding encountered
- invalid characters encountered in Hex data
- a hexadecimal encoding must have an even number of character
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/f7a3f8d9aa0302b6.
Report an issue: GitHub.