qax-os/excelize · error
ErrUnknownEncryptMechanism
ErrUnknownEncryptMechanism
Error message
unknown encryption mechanism
What it means
ErrUnknownEncryptMechanism indicates that the workbook's encrypted package did not contain enough bytes to read an encryption mechanism specifier (fewer than 4 bytes). The library throws it from encryptionMechanism when parsing the EncryptionInfo stream of an encrypted XLSX file and the header is too short to identify the mechanism.
Source
Thrown at errors.go:179
ErrSparklineLocation = errors.New("parameter 'Location' is required")
// ErrSparklineRange defined the error message on missing sparkline Range
// parameters
ErrSparklineRange = errors.New("parameter 'Range' is required")
// ErrSparklineStyle defined the error message on receive the invalid
// sparkline Style parameters.
ErrSparklineStyle = errors.New("parameter 'Style' value must be an integer from 0 to 35")
// ErrSparklineType defined the error message on receive the invalid
// sparkline Type parameters.
ErrSparklineType = errors.New("parameter 'Type' value must be one of 'line', 'column' or 'win_loss'")
// ErrTotalSheetHyperlinks defined the error message on hyperlinks count
// overflow.
ErrTotalSheetHyperlinks = errors.New("over maximum limit hyperlinks in a worksheet")
// ErrTransparency defined the error message for receiving a transparency
// value exceeds limit.
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")View on GitHub (pinned to f2483381fb)
Solutions
- Verify the file is a valid, complete encrypted XLSX (OLE compound file with non-empty EncryptionInfo stream)
- Re-export or re-download the workbook to repair truncation/corruption
- If encrypting, ensure the password/options passed to SaveAs/Encrypt are valid so a proper EncryptionInfo is written
Example fix
// before
f, err := OpenFile("corrupted-truncated.xlsx")
// after
info, _ := os.Stat("file.xlsx")
if info.Size() < 1024 { return errors.New("file looks truncated") }
f, err := OpenFile("file.xlsx") Defensive patterns
Strategy: type-guard
Validate before calling
info, err := os.Stat(path)
if err != nil || info.Size() < 1024 { /* likely truncated; skip */ }
// also check it is an OLE compound file (starts with D0 CF 11 E0) before opening encrypted files Type guard
func looksEncrypted(data []byte) bool {
return len(data) > 8 && bytes.Equal(data[:8], []byte{0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1})
} Try / catch
f, err := excelize.OpenFile(path)
if errors.Is(err, excelize.ErrUnknownEncryptMechanism) {
return fmt.Errorf("%s is not a valid encrypted workbook", path)
} Prevention
- Validate file size and header signature before opening
- Only open encrypted workbooks produced by Excel or excelize itself
- Handle truncation from incomplete downloads/uploads
When it happens
Trigger: Calling OpenReader/OpenFile (or Decrypt) on a file whose EncryptionInfo stream is empty or shorter than 4 bytes; in tests this is triggered by encryptionMechanism([]byte{}).
Common situations: Opening a corrupted or truncated encrypted workbook; passing a non-OLE compound file or an empty EncryptionInfo stream; a file produced by a broken encryption tool.
Related errors
- ErrWorkbookFileFormat
- ErrPasswordLengthInvalid
- ErrUnsupportedEncryptMechanism
- fill type value must be one of 'gradient' or 'pattern'
- fill color value must be an array of two colors for 'gradien
AI-assisted analysis of qax-os/excelize@f2483381fb (2026-09-02).
Data as JSON: /api/errors/c642a3e2d95a2133.
Report an issue: GitHub.