{"record":{"id":"4414348445e4885b","repo":"juicedata/juicefs","slug":"new-cipher-s","errorCode":null,"errorMessage":"new cipher: %s","messagePattern":"new cipher: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/config.go","lineNumber":223,"sourceCode":"}\n\nfunc newCipher(algo string, key string) (cipher.AEAD, error) {\n\tswitch algo {\n\tcase object.SM4GCM:\n\t\tblock, err := sm4.NewCipher(sm3.Kdf([]byte(key), 16))\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"new sm4 cipher: %s\", err)\n\t\t}\n\t\taead, err := cipher.NewGCM(block)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"new sm4 GCM: %s\", err)\n\t\t}\n\t\treturn aead, nil\n\tdefault:\n\t\thashKey := md5.Sum([]byte(key))\n\t\tblock, err := aes.NewCipher(hashKey[:])\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"new cipher: %s\", err)\n\t\t}\n\t\taead, err := cipher.NewGCM(block)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"new GCM: %s\", err)\n\t\t}\n\t\treturn aead, nil\n\t}\n}\n\nfunc (f *Format) Encrypt() error {\n\tif f.KeyEncrypted || f.SecretKey == \"\" && f.EncryptKey == \"\" && f.SessionToken == \"\" {\n\t\treturn nil\n\t}\n\tci, err := newCipher(f.EncryptAlgo, f.UUID)\n\tif err != nil {\n\t\treturn err\n\t}\n\tencrypt := func(k *string) {","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/config.go#L205-L241","documentation":"Returned by newCipher in pkg/meta/config.go when aes.NewCipher fails on the MD5-hashed key in the default encryption branch. Since the key is always a fixed 16-byte MD5 sum, aes.NewCipher can essentially never fail; this wraps an unexpected crypto-internal error. It surfaces via Format.Encrypt/Decrypt during volume format load/save.","triggerScenarios":"Format.Encrypt() or Format.Decrypt() on the default algorithm path where aes.NewCipher(md5hash) returns an error (only possible with a broken crypto backend).","commonSituations":"Practically unreachable; encountered only with non-standard Go crypto builds or heavily patched environments.","solutions":["Inspect the wrapped error text and verify the Go crypto/aes package is intact (rebuild with a stock toolchain)","If key handling was customized, ensure the key passed to Encrypt/Decrypt is non-nil string input to md5.Sum","Switch to a different EncryptAlgorithm via `juicefs config` to isolate the failure"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if f.EncryptAlgorithm == \"\" || f.EncryptAlgorithm == \"aes256\" { /* stock toolchain guarantees AES support */ }","typeGuard":null,"tryCatchPattern":"if err := format.Decrypt(); err != nil { if strings.Contains(err.Error(), \"new cipher\") { /* rebuild with stock Go toolchain */ } }","preventionTips":["Build with unmodified Go toolchains","Round-trip test encryption after toolchain upgrades"],"tags":["crypto","encryption","aes","config"],"backgroundTag":"module-init-failed","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}