qax-os/excelize · error

ErrUnsupportedEncryptMechanism

ErrUnsupportedEncryptMechanism

Error message

unsupported encryption mechanism

What it means

ErrUnsupportedEncryptMechanism indicates that the workbook's EncryptionInfo declares an encryption mechanism the library cannot handle. encryptionMechanism parses the header; known mechanisms are consumed, otherwise the function returns this error (crypt.go:229 default branch).

Source

Thrown at errors.go:194

	ErrTransparency = errors.New("transparency value must be an integer from 0 to 100")
	// ErrUnknownEncryptMechanism defined the error message on unsupported
	// encryption mechanism.
	ErrUnknownEncryptMechanism = errors.New("unknown encryption mechanism")
	// ErrUnprotectSheet defined the error message on worksheet has set no
	// protection.
	ErrUnprotectSheet = errors.New("worksheet has set no protect")
	// ErrUnprotectSheetPassword defined the error message on remove sheet
	// protection with password verification failed.
	ErrUnprotectSheetPassword = errors.New("worksheet protect password not match")
	// ErrUnprotectWorkbook defined the error message on workbook has set no
	// protection.
	ErrUnprotectWorkbook = errors.New("workbook has set no protect")
	// ErrUnprotectWorkbookPassword defined the error message on remove workbook
	// protection with password verification failed.
	ErrUnprotectWorkbookPassword = errors.New("workbook protect password not match")
	// ErrUnsupportedEncryptMechanism defined the error message on unsupported
	// encryption mechanism.
	ErrUnsupportedEncryptMechanism = errors.New("unsupported encryption mechanism")
	// ErrUnsupportedHashAlgorithm defined the error message on unsupported
	// hash algorithm.
	ErrUnsupportedHashAlgorithm = errors.New("unsupported hash algorithm")
	// ErrUnsupportedNumberFormat defined the error message on unsupported
	// number format expression.
	ErrUnsupportedNumberFormat = errors.New("unsupported number format token")
	// ErrUnsupportedPivotTableShowValuesAsType defined the error message on
	// receiving the unsupported pivot table "show values as" type.
	ErrUnsupportedPivotTableShowValuesAsType = errors.New("unsupported pivot table show values as type")
	// ErrWorkbookFileFormat defined the error message on receive an
	// unsupported workbook file format.
	ErrWorkbookFileFormat = errors.New("unsupported workbook file format")
	// ErrWorkbookPassword defined the error message on receiving the incorrect
	// workbook password.
	ErrWorkbookPassword = errors.New("the supplied open workbook password is not correct")
)

// ErrSheetNotExist defined an error of sheet that does not exist.

View on GitHub (pinned to f2483381fb)

Solutions

  1. Re-save the workbook with standard Excel encryption supported by excelize
  2. Decrypt the file with the tool that produced it before opening with excelize
  3. Upgrade excelize, which may add support for more mechanisms

Example fix

// before
f, err := OpenFile("thirdparty-encrypted.xlsx") // unsupported mechanism
// after
cmd := exec.Command("tool", "--decrypt", "thirdparty-encrypted.xlsx") // decrypt externally first
f, err := OpenFile("decrypted.xlsx")
Defensive patterns

Strategy: fallback

Validate before calling

// check the OLE EncryptionInfo stream header before decrypting; only proceed for mechanisms excelize documents as supported

Type guard

func isKnownMechanism(header []byte) bool {
	return len(header) >= 4 // + whitelist known 4-byte mechanism specifiers
}

Try / catch

f, err := excelize.OpenReader(r)
if errors.Is(err, excelize.ErrUnsupportedEncryptMechanism) {
	return decryptExternallyThenOpen(r)
}
return err

Prevention

When it happens

Trigger: Decrypt/OpenReader on a file whose EncryptionInfo header bytes name an unsupported mechanism; tests set raw[2050]=3 (e.g. AES-ish/unknown specifier) to trigger it; also the fall-through after mechanism="extensible".

Common situations: Files encrypted with non-standard or third-party encryption schemes (e.g. agile encryption variants excelize does not support); files encrypted by other tools.

Related errors


AI-assisted analysis of qax-os/excelize@f2483381fb (2026-09-02). Data as JSON: /api/errors/068fe3cad1a3d17d. Report an issue: GitHub.