siyuan-note/siyuan · error
Conf.Language(316)
Error message
Conf.Language(316)
What it means
ImportNotebookCryptoBackup returns Conf.Language(316) (密钥不匹配 / key mismatch) when the imported backup's KEK cannot unwrap the WrappedDEKs of the notebooks (or deleted-notebook history) already present on this machine — verifyKEKAgainstExistingBoxes or verifyKEKAgainstEncryptedHistory fails. The guard prevents importing a backup that would lock the user out of locally existing encrypted data; the backup and the local data belong to different key hierarchies.
Solutions
- Import the backup that matches the keys used to encrypt the notebooks currently in this workspace (same device/workspace of origin)
- If local notebooks are already inaccessible or unwanted, remove/re-export them first so the mismatch check has nothing to contradict
- Verify the backup origin: re-export from the workspace that actually encrypted the existing notebooks
- Do not disable or bypass the verification — it exists to prevent permanent data lockout
Defensive patterns
Strategy: validation
Validate before calling
// Before import, confirm the backup belongs to this workspace: // compare a non-secret identifier (BackupID/CreatedAt) with the workspace's history, or // verify at least one local notebook's WrappedDEK unwraps with the same password // via the API surface before calling the destructive import.
Type guard
null
Try / catch
if err := ImportNotebookCryptoBackup(raw, password); err != nil {
if strings.Contains(err.Error(), Conf.Language(316)) {
// backup keys ≠ local notebook keys: stop and locate the matching backup
return ErrKeyMismatch
}
return err
} Prevention
- Label each backup export with its workspace and creation date
- Never mix backups between workspaces or machines
- After password changes, always export a fresh backup and retire old ones
- Test the import on a copy of the workspace before touching production data
When it happens
Trigger: Calling ImportNotebookCryptoBackup on a workspace whose existing encrypted notebooks (or deleted-history boxes) were encrypted with keys from a different master password/salt than the imported backup; importing a backup from another workspace onto a machine that already has notebooks encrypted under different keys.
Common situations: Mixing backups between two workspaces or two machines; restoring a very old backup whose keys predate the local notebooks; after re-enabling encryption with a new password, importing the old backup; sync partially applied so local boxes use different keys than the backup.
Related errors
- Conf.Language(311)
- Conf.Language(317)
- Conf.Language(324)
- 26
- Access to encrypted notebook data is not supported via this…
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/67d51c67d2af84f7.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/crypto.go:357
if validErr != nil {
return errors.New(Conf.Language(317))
}
kek := util.DeriveKey(password, nc.MasterSalt, params)
defer zeroAndClear(kek)
if nc.Checksum != computeBackupChecksum(nc) {
return errors.New(Conf.Language(317))
}
if !verifyKEKMAC(nc, kek) {
return errors.New(Conf.Language(317))
}
decrypted, dErr := util.DecryptWithAAD(kek, nc.KEKVerifier, []byte("siyuan:kek-verifier"))
if dErr != nil || string(decrypted) != string(kekVerifierMagic) {
return errors.New(Conf.Language(311)) // 主密码错误
}
// 校验 KEK 能解密现存笔记本和已删除笔记本历史中的 WrappedDEK,避免导入不匹配的备份。
if !verifyKEKAgainstExistingBoxes(kek, nc) || !verifyKEKAgainstEncryptedHistory(kek, nc) {
return errors.New(Conf.Language(316)) // 密钥不匹配
}
nc.KDFParams = params // 确保写回 Conf 的参数已经通过完整校验。
nc.Enabled = true
// 先写 backup,再提交 conf;backup 失败时 conf 尚未改变,可重试
if err := writeNotebookCryptoBackupData(nc, kek); err != nil {
return fmt.Errorf("failed to persist key backup: %w", err)
}
Conf.m.Lock()
*Conf.NotebookCrypto = *nc
Conf.m.Unlock()
Conf.Save()
IncSync()
return nil
}
// saveNotebookCryptoBackup 把当前 NotebookCrypto(含 MasterSalt/KEKVerifier/KDFParams)备份到 DataDir。View on GitHub (pinned to 9f775e8a12)