moonD4rk/HackBrowserData · error

invalid PKCS5 padding

Error message

invalid PKCS5 padding

What it means

errInvalidPadding is returned by pkcs5UnPadding after CBC decryption when the decrypted plaintext does not carry valid PKCS5 padding: the buffer is empty, the final byte is 0 or exceeds the block size/data length, or the trailing bytes do not all equal the pad count. It almost always means decryption used the wrong key or IV, producing garbage that fails the padding check.

Source

Thrown at crypto/errors.go:10

package crypto

import "errors"

// Sentinel errors for crypto operations.
var (
	errShortCiphertext   = errors.New("ciphertext too short")
	errInvalidBlockSize  = errors.New("ciphertext is not a multiple of the block size")
	errInvalidIVLength   = errors.New("IV length must equal block size")
	errInvalidPadding    = errors.New("invalid PKCS5 padding")
	errInvalidNonceLen   = errors.New("nonce length must equal GCM nonce size")
	errUnsupportedIVLen  = errors.New("unsupported IV length")
	errDecodeASN1        = errors.New("failed to decode ASN1 data")
	errDPAPINotSupported = errors.New("DPAPI not supported on this platform") //nolint:unused // used on darwin/linux only
)

View on GitHub (pinned to 0503d04d7a)

Solutions

  1. Verify the key derivation: correct profile app-bound/safe-storage key, correct PBKDF2 iterations and salt for Firefox.
  2. Confirm algorithm match: 3DES vs AES-CBC based on the PBE OID / browser version.
  3. Re-copy the database to rule out corruption, and check the ciphertext offset is right.
  4. Treat errInvalidPadding as a wrong-key signal — do not retry with the same key; log and skip the record.

Example fix

// before
key, _ := getKeyFromLocalState()
plain, err := crypto.DecryptChromiumCBC(key, iv, ct) // fails padding
// after
key, err := getKeyFromLocalState()
if err != nil {
    return fmt.Errorf("key derivation failed: %w", err)
}
plain, err := crypto.DecryptChromiumCBC(key, iv, ct)
Defensive patterns

Strategy: try-catch

Validate before calling

// no reliable pre-check: padding validity is only knowable after decryption with the right key

Try / catch

plain, err := crypto.DecryptChromiumCBC(key, iv, ct)
if errors.Is(err, crypto.ErrInvalidPadding) {
    return fmt.Errorf("decryption failed (wrong key or IV?): %w", err)
}

Prevention

When it happens

Trigger: Any CBC decrypt path (DecryptChromiumCBC, 3DES decrypt, PBE decrypt) where the key is wrong, the IV is wrong, or the ciphertext was corrupted — padding validation then rejects the plaintext.

Common situations: Wrong master key (wrong profile key from Local State, wrong safe-storage password for Firefox); decryption done with AES when the blob is 3DES (old Firefox) or vice versa; bit-flip corruption from a bad DB copy; misaligned ciphertext offset in PBE parsing.

Related errors


AI-assisted analysis of moonD4rk/HackBrowserData@0503d04d7a (2026-09-06). Data as JSON: /api/errors/650b8bd117685b4f. Report an issue: GitHub.