siyuan-note/siyuan · error

Conf.Language(311)

Error message

Conf.Language(311)

What it means

ImportNotebookCryptoBackup returns Conf.Language(311) (主密码错误 / wrong master password) when the KEK derived from the supplied password cannot decrypt the backup's KEKVerifier blob to the expected magic value via util.DecryptWithAAD with AAD "siyuan:kek-verifier". This is the password check: the verifier only decrypts under the correct master password, so failure means the entered password is wrong (or the verifier blob is corrupted).

Solutions

  1. Re-enter the current master password and retry
  2. If the password was changed after the backup was exported, export a new backup under the current password and import that
  3. Check for keyboard/input-method issues (Caps Lock, IME layout)
  4. If the password is truly lost, the backup cannot be imported — encrypted notebooks remain unrecoverable by design

Example fix

// before
err := ImportNotebookCryptoBackup(raw, "old-password") // -> Conf.Language(311)
// after: use the master password current at backup creation
err := ImportNotebookCryptoBackup(raw, currentMasterPassword)
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

null

Try / catch

if err := ImportNotebookCryptoBackup(raw, password); err != nil {
    if strings.Contains(err.Error(), Conf.Language(311)) {
        // wrong master password: prompt again, do NOT fall back to other passwords blindly
        return ErrWrongMasterPassword
    }
    return err
}

Prevention

When it happens

Trigger: Calling ImportNotebookCryptoBackup(data, password) where decrypting nc.KEKVerifier with the derived KEK fails or the plaintext does not equal kekVerifierMagic — i.e. the password argument is not the master password that was active when the backup was created.

Common situations: Typo in the master password during recovery on a new device; using an old password that was changed after the backup was exported; Caps Lock or input-method issues; passing an empty or test password in scripts.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/c20ede1590dc6f21. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/crypto.go:352

		return errors.New(Conf.Language(317))
	}

	// 用导入的 salt + 用户输入的主密码派生 KEK,校验能否解开备份里的 verifier
	params, validErr := util.ValidateArgon2Params(nc.KDFParams)
	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()

View on GitHub (pinned to 9f775e8a12)