{"record":{"id":"2bade744ecbd5a85","repo":"beemdevelopment/Aegis","slug":"secret-is-not-valid-hexadecimal","errorCode":null,"errorMessage":"Secret is not valid hexadecimal","messagePattern":"Secret is not valid hexadecimal","errorType":"validation","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/com/beemdevelopment/aegis/ui/EditEntryActivity.java","lineNumber":757,"sourceCode":"        } catch (NumberFormatException e) {\n            throw new ParseException(\"Digits is not an integer.\");\n        }\n\n        byte[] secret;\n        try {\n            String secretString = new String(EditTextHelper.getEditTextChars(_textSecret));\n\n            secret = (lowerCasedType.equals(MotpInfo.ID)) ?\n                    Hex.decode(secretString) : GoogleAuthInfo.parseSecret(secretString);\n\n            if (secret.length == 0) {\n                throw new ParseException(\"Secret cannot be empty\");\n            }\n        } catch (EncodingException e) {\n            String exceptionMessage = (lowerCasedType.equals(MotpInfo.ID)) ?\n                    \"Secret is not valid hexadecimal\" : \"Secret is not valid base32.\";\n\n            throw new ParseException(exceptionMessage);\n        }\n\n        OtpInfo info;\n        try {\n            switch (type.toLowerCase(Locale.ROOT)) {\n                case TotpInfo.ID:\n                    info = new TotpInfo(secret, algo, digits, parsePeriod());\n                    break;\n                case SteamInfo.ID:\n                    info = new SteamInfo(secret, algo, digits, parsePeriod());\n                    break;\n                case HotpInfo.ID:\n                    long counter;\n                    try {\n                        counter = Long.parseLong(_textPeriodCounter.getText().toString());\n                    } catch (NumberFormatException e) {\n                        throw new ParseException(\"Counter is not an integer.\");\n                    }","sourceCodeStart":739,"sourceCodeEnd":775,"githubUrl":"https://github.com/beemdevelopment/Aegis/blob/d6f4e5925a97e4e91593f1542085eae03432a759/app/src/main/java/com/beemdevelopment/aegis/ui/EditEntryActivity.java#L739-L775","documentation":"EditEntryActivity.parseEntry() decodes the secret inside a try block catching EncodingException; on failure it builds the message 'Secret is not valid hexadecimal' for MOTP entries (or 'not valid base32' otherwise). This variant fires when a MOTP entry's secret is not a valid hex string, since Hex.decode rejects invalid characters or odd length.","triggerScenarios":"Saving an entry with type MotpInfo.ID whose secret contains non-hex characters (G-Z) or has an odd number of characters, causing Hex.decode to throw EncodingException.","commonSituations":"Pasting a base32 secret into a MOTP entry, typos like 'O' vs '0', or copying a truncated/odd-length hex string from the provider.","solutions":["Enter a valid hexadecimal string (0-9, A-F, even length) as the MOTP secret","Check for lookalike characters (O vs 0, I vs 1) and correct them","Confirm the entry type: if your secret is base32, switch the type to TOTP/HOTP instead of MOTP"],"exampleFix":"// before\nsecretField.setText(\"GXYZ\"); // G, Y, Z not hex; odd-ish\n// after\nsecretField.setText(\"0ABC\");","handlingStrategy":"validation","validationCode":"if (type.equals(\"motp\") && !secret.matches(\"([0-9A-Fa-f]{2})+\")) {\n    _textSecretLayout.setError(\"MOTP secret must be valid hex (even length)\");\n    return;\n}","typeGuard":null,"tryCatchPattern":"try {\n    saveEntry();\n} catch (ParseException e) {\n    if (\"Secret is not valid hexadecimal\".equals(e.getMessage())) {\n        _textSecretLayout.setError(\"Enter a valid hex string\");\n    }\n}","preventionTips":["Validate hex format with a regex before saving MOTP entries","Ensure even-length hex strings","Confirm the entry type matches the secret encoding (hex=motp, base32=totp/hotp)"],"tags":["android","validation","otp","hex","encoding"],"backgroundTag":"invalid-argument-format","analyzedSha":"d6f4e5925a97e4e91593f1542085eae03432a759","analyzedAt":"2026-09-08T00:46:31.111Z","contentChangedAt":"2026-09-08T00:46:31.111Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}