{"record":{"id":"c642a3e2d95a2133","repo":"qax-os/excelize","slug":"errunknownencryptmechanism","errorCode":"ErrUnknownEncryptMechanism","errorMessage":"unknown encryption mechanism","messagePattern":"unknown encryption mechanism","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":179,"sourceCode":"\tErrSparklineLocation = errors.New(\"parameter 'Location' is required\")\n\t// ErrSparklineRange defined the error message on missing sparkline Range\n\t// parameters\n\tErrSparklineRange = errors.New(\"parameter 'Range' is required\")\n\t// ErrSparklineStyle defined the error message on receive the invalid\n\t// sparkline Style parameters.\n\tErrSparklineStyle = errors.New(\"parameter 'Style' value must be an integer from 0 to 35\")\n\t// ErrSparklineType defined the error message on receive the invalid\n\t// sparkline Type parameters.\n\tErrSparklineType = errors.New(\"parameter 'Type' value must be one of 'line', 'column' or 'win_loss'\")\n\t// ErrTotalSheetHyperlinks defined the error message on hyperlinks count\n\t// overflow.\n\tErrTotalSheetHyperlinks = errors.New(\"over maximum limit hyperlinks in a worksheet\")\n\t// ErrTransparency defined the error message for receiving a transparency\n\t// value exceeds limit.\n\tErrTransparency = errors.New(\"transparency value must be an integer from 0 to 100\")\n\t// ErrUnknownEncryptMechanism defined the error message on unsupported\n\t// encryption mechanism.\n\tErrUnknownEncryptMechanism = errors.New(\"unknown encryption mechanism\")\n\t// ErrUnprotectSheet defined the error message on worksheet has set no\n\t// protection.\n\tErrUnprotectSheet = errors.New(\"worksheet has set no protect\")\n\t// ErrUnprotectSheetPassword defined the error message on remove sheet\n\t// protection with password verification failed.\n\tErrUnprotectSheetPassword = errors.New(\"worksheet protect password not match\")\n\t// ErrUnprotectWorkbook defined the error message on workbook has set no\n\t// protection.\n\tErrUnprotectWorkbook = errors.New(\"workbook has set no protect\")\n\t// ErrUnprotectWorkbookPassword defined the error message on remove workbook\n\t// protection with password verification failed.\n\tErrUnprotectWorkbookPassword = errors.New(\"workbook protect password not match\")\n\t// ErrUnsupportedEncryptMechanism defined the error message on unsupported\n\t// encryption mechanism.\n\tErrUnsupportedEncryptMechanism = errors.New(\"unsupported encryption mechanism\")\n\t// ErrUnsupportedHashAlgorithm defined the error message on unsupported\n\t// hash algorithm.\n\tErrUnsupportedHashAlgorithm = errors.New(\"unsupported hash algorithm\")","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L161-L197","documentation":"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.","triggerScenarios":"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{}).","commonSituations":"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.","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"],"exampleFix":"// before\nf, err := OpenFile(\"corrupted-truncated.xlsx\")\n// after\ninfo, _ := os.Stat(\"file.xlsx\")\nif info.Size() < 1024 { return errors.New(\"file looks truncated\") }\nf, err := OpenFile(\"file.xlsx\")","handlingStrategy":"type-guard","validationCode":"info, err := os.Stat(path)\nif err != nil || info.Size() < 1024 { /* likely truncated; skip */ }\n// also check it is an OLE compound file (starts with D0 CF 11 E0) before opening encrypted files","typeGuard":"func looksEncrypted(data []byte) bool {\n\treturn len(data) > 8 && bytes.Equal(data[:8], []byte{0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1})\n}","tryCatchPattern":"f, err := excelize.OpenFile(path)\nif errors.Is(err, excelize.ErrUnknownEncryptMechanism) {\n\treturn fmt.Errorf(\"%s is not a valid encrypted workbook\", path)\n}","preventionTips":["Validate file size and header signature before opening","Only open encrypted workbooks produced by Excel or excelize itself","Handle truncation from incomplete downloads/uploads"],"tags":["go","excelize","encryption","file-parsing"],"backgroundTag":"unsupported-encryption-mechanism","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}