beemdevelopment/Aegis · error

unsupported algorithm

Error message

unsupported algorithm: %s

What it means

OtpInfo.setAlgorithm normalizes the algorithm name (strips an optional 'Hmac' prefix, uppercases) and validates it against the supported set (SHA1/SHA256/SHA512) via isAlgorithmValid. If the value is not supported it throws OtpInfoException('unsupported algorithm: %s').

Solutions

  1. Use a supported algorithm in the URI/entry: SHA1, SHA256, or SHA512 (the 'Hmac' prefix and any casing are normalized automatically).
  2. Before calling setAlgorithm, validate with OtpInfo.isAlgorithmValid(normalizedName) and handle unsupported values at import time.
  3. If the source credential genuinely requires an unsupported algorithm, re-issue it with SHA1/SHA256/SHA512.

Example fix

// before
String algo = uri.getQueryParameter("algorithm"); // "MD5"
info.setAlgorithm(algo); // throws

// after
String algo = uri.getQueryParameter("algorithm");
if (algo != null && algo.startsWith("Hmac")) algo = algo.substring(4);
algo = algo == null ? null : algo.toUpperCase(Locale.ROOT);
if (algo != null && !OtpInfo.isAlgorithmValid(algo)) {
    algo = null; // fall back to default SHA1 or reject entry
}
if (algo != null) info.setAlgorithm(algo);
Defensive patterns

Strategy: validation

Validate before calling

String norm = algorithm == null ? null
    : (algorithm.startsWith("Hmac") ? algorithm.substring(4) : algorithm).toUpperCase(Locale.ROOT);
if (norm != null && !OtpInfo.isAlgorithmValid(norm)) {
    throw new IllegalArgumentException("unsupported algorithm: " + norm);
}

Type guard

boolean isSupportedAlgorithm(String algo) {
    if (algo == null) return false;
    String n = algo.startsWith("Hmac") ? algo.substring(4) : algo;
    return OtpInfo.isAlgorithmValid(n.toUpperCase(Locale.ROOT));
}

Try / catch

try {
    otpInfo.setAlgorithm(algorithmParam);
} catch (OtpInfoException e) {
    // unsupported algorithm from imported URI/entry; fall back to SHA1 or reject entry
    otpInfo.setAlgorithm("SHA1");
}

Prevention

When it happens

Trigger: parseUri on an otpauth:// URI whose algorithm parameter is not SHA1/SHA256/SHA512 (after normalization); parseEntry importing a vault entry with an unknown algorithm string; calling the OtpInfo constructor or setAlgorithm directly with e.g. 'MD5', 'SHA224', or a misspelled name.

Common situations: Importing credentials generated by other apps that emit algorithms Aegis doesn't support (MD5, SHA3) — e.g. some FreeOTP/andOTP exports; typos in hand-written otpauth URIs; case differences are tolerated but unsupported families are not.

Related errors


AI-assisted analysis of beemdevelopment/Aegis@d6f4e5925a (2026-09-08). Data as JSON: /api/errors/b09489ec7842e025. Report an issue: GitHub.

Appendix: source

Thrown at app/src/main/java/com/beemdevelopment/aegis/otp/OtpInfo.java:90

    }

    public void setSecret(byte[] secret) {
        _secret = secret;
    }

    public static boolean isAlgorithmValid(String algorithm) {
        return algorithm.equals("SHA1") || algorithm.equals("SHA256") ||
                algorithm.equals("SHA512") || algorithm.equals("MD5");
    }

    public void setAlgorithm(String algorithm) throws OtpInfoException {
        if (algorithm.startsWith("Hmac")) {
            algorithm = algorithm.substring(4);
        }
        algorithm = algorithm.toUpperCase(Locale.ROOT);

        if (!isAlgorithmValid(algorithm)) {
            throw new OtpInfoException(String.format("unsupported algorithm: %s", algorithm));
        }
        _algorithm = algorithm;
    }

    public static boolean isDigitsValid(int digits) {
        // allow a max of 10 digits, as truncation will only extract 31 bits
        return digits > 0 && digits <= 10;
    }

    public void setDigits(int digits) throws OtpInfoException {
        if (!isDigitsValid(digits)) {
            throw new OtpInfoException(String.format("unsupported amount of digits: %d", digits));
        }
        _digits = digits;
    }

    public static OtpInfo fromJson(String type, JSONObject obj) throws OtpInfoException {
        OtpInfo info;

View on GitHub (pinned to d6f4e5925a)