{"record":{"id":"6b87e40c13e2744b","repo":"AlistGo/alist","slug":"failed-to-encryptdata-w","errorCode":null,"errorMessage":"failed to EncryptData: %w","messagePattern":"failed to EncryptData: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/crypt/driver.go","lineNumber":376,"sourceCode":"\nfunc (d *Crypt) Remove(ctx context.Context, obj model.Obj) error {\n\tremoteActualPath, err := d.getActualPathForRemote(obj.GetPath(), obj.IsDir())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to convert path to remote path: %w\", err)\n\t}\n\treturn op.Remove(ctx, d.remoteStorage, remoteActualPath)\n}\n\nfunc (d *Crypt) Put(ctx context.Context, dstDir model.Obj, streamer model.FileStreamer, up driver.UpdateProgress) error {\n\tdstDirActualPath, err := d.getActualPathForRemote(dstDir.GetPath(), true)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to convert path to remote path: %w\", err)\n\t}\n\n\t// Encrypt the data into wrappedIn\n\twrappedIn, err := d.cipher.EncryptData(streamer)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to EncryptData: %w\", err)\n\t}\n\n\t// doesn't support seekableStream, since rapid-upload is not working for encrypted data\n\tstreamOut := &stream.FileStream{\n\t\tObj: &model.Object{\n\t\t\tID:       streamer.GetID(),\n\t\t\tPath:     streamer.GetPath(),\n\t\t\tName:     d.cipher.EncryptFileName(streamer.GetName()),\n\t\t\tSize:     d.cipher.EncryptedSize(streamer.GetSize()),\n\t\t\tModified: streamer.ModTime(),\n\t\t\tIsFolder: streamer.IsDir(),\n\t\t},\n\t\tReader:            wrappedIn,\n\t\tMimetype:          \"application/octet-stream\",\n\t\tWebPutAsTask:      streamer.NeedStore(),\n\t\tForceStreamUpload: true,\n\t\tExist:             streamer.GetExist(),\n\t}","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/crypt/driver.go#L358-L394","documentation":"Thrown by Crypt.Put when the rclone crypt cipher fails to wrap the input stream with EncryptData. EncryptData builds an encrypting reader over the file streamer; it fails when the cipher was constructed with incompatible parameters for streaming encryption or when the input stream cannot be adapted (e.g. nil/invalid streamer characteristics after the path already resolved fine). The upload aborts before any data reaches the remote.","triggerScenarios":"Uploading a file through the crypt mount when the cipher's configuration makes stream encryption fail — most commonly a corrupted or wrong-version password/salt pair that slipped past NewCipher, or an upstream rclone library change where EncryptData rejects the stream wrapper (nil reader, unsupported ReaderAt expectations).","commonSituations":"AList/rclone-library version mismatch after upgrade while old obscured credentials remain in the DB; storage record hand-edited so the cipher is half-initialized; very old crypt storage created by a much earlier AList version.","solutions":["Re-enter password and salt in the admin UI and re-save the crypt storage so a fresh cipher is built","Upgrade AList to a consistent version (bundled rclone library matches driver code)","Check the wrapped error message — 'bad password' style errors mean credentials; stream errors mean the FileStreamer setup","Re-create the crypt storage if the existing record keeps failing after credential re-entry"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before upload, verify the cipher works on a tiny buffer\nif _, err := d.cipher.EncryptData(bytes.NewReader([]byte(\"probe\"))); err != nil {\n    return fmt.Errorf(\"cipher unusable, re-enter credentials: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := d.Put(ctx, dstDir, streamer, up); err != nil {\n    if strings.Contains(err.Error(), \"failed to EncryptData\") {\n        // cipher/credential problem: re-save storage with fresh password+salt, then retry upload\n        return fmt.Errorf(\"encryption failed, refresh crypt credentials and retry: %w\", err)\n    }\n    return err\n}","preventionTips":["Re-enter crypt credentials after major version upgrades","Never hand-edit obscured password/salt values in the DB","Run a small test upload after configuring or upgrading a crypt storage"],"tags":["crypt","upload","cipher","streaming"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}