usebruno/bruno · error · Error
Decrypt failed: unrecognized string format
Error message
Decrypt failed: unrecognized string format
What it means
Thrown by decryptString when typeof str !== 'string'. This is the input-type guard at the top of the function, before any format parsing. It fires when the caller hands in null, undefined, a Buffer, a number, or an object instead of a string.
Source
Thrown at packages/bruno-electron/src/utils/encryption.js:131
return `$${AES256_ALGO}:${encryptedString}`;
} catch (err) {
// Any error indicates the passkey is unusable; return empty string
return '';
}
}
if (safeStorage && safeStorage.isEncryptionAvailable()) {
const encryptedString = safeStorageEncrypt(str);
return `$${ELECTRONSAFESTORAGE_ALGO}:${encryptedString}`;
}
const encryptedString = aes256Encrypt(str);
return `$${AES256_ALGO}:${encryptedString}`;
}
function decryptString(str, passkey = null) {
if (typeof str !== 'string') {
throw new Error('Decrypt failed: unrecognized string format');
}
if (str.length === 0) {
return '';
}
// Find the index of the first colon
const colonIndex = str.indexOf(':');
if (colonIndex === -1) {
throw new Error('Decrypt failed: unrecognized string format');
}
// Extract algo and encryptedString based on the colon index
const algo = str.substring(1, colonIndex);
const encryptedString = str.substring(colonIndex + 1);
if ([ELECTRONSAFESTORAGE_ALGO, AES256_ALGO].indexOf(algo) === -1) {
throw new Error('Decrypt failed: Invalid algo');View on GitHub (pinned to 9bdd81c7bd)
Solutions
- Null/empty-check before calling decryptString (empty string short-circuits to '' inside the function, so coerce null/undefined to '').
- If you hold a Buffer, call .toString('hex') or the appropriate encoding first.
- Prefer decryptStringSafe which returns {success:false} instead of throwing on bad input.
Example fix
// before
const plain = decryptString(maybeMissing);
// after
const plain = (typeof maybeMissing === 'string' && maybeMissing.length)
? decryptString(maybeMissing)
: '';
// or simply:
const { value } = decryptStringSafe(maybeMissing ?? ''); Defensive patterns
Strategy: type-guard
Validate before calling
function decryptStringOrEmpty(str) {
if (typeof str !== 'string') return '';
if (str.length === 0) return '';
return decryptString(str);
} Type guard
function isEncryptedString(value) {
return typeof value === 'string';
} Try / catch
const { success, value } = decryptStringSafe(typeof stored === 'string' ? stored : '');
return success ? value : ''; Prevention
- Coerce null/undefined to '' before calling decryptString.
- Convert Buffers to strings with the correct encoding first.
- Prefer decryptStringSafe in all read paths.
When it happens
Trigger: Calling decryptString(null), decryptString(undefined), or decryptString(someBuffer) — typically because a missing DB/config value was forwarded without a presence check, or a Buffer was not first converted to a string.
Common situations: Optional secret field not populated in storage and passed through unguarded; refactor changed the stored type from string to Buffer/JSON; value loaded from a column that returned null.
Related errors
- WSDL content must be a string
- AES256 decryption failed: ${fallbackErr.message}
- SafeStorage decryption failed: ${err.message}
- Decrypt failed: Invalid algo
- directory: path is null
AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13).
Data as JSON: /api/errors/c5ffcccd9f50edfa.
Report an issue: GitHub.