siyuan-note/siyuan · error

The key is not recognized, please confirm that the copied ke

Error message

The key is not recognized, please confirm that the copied key string is correct

What it means

ImportRepoKey: the trimmed input is non-empty but base64.StdEncoding.DecodeString fails (illegal characters / wrong alphabet / bad padding). Returns i18n key 157 ('The key is not recognized...'). The original decode error is logged but not surfaced to the user.

Source

Thrown at kernel/model/repository.go:1102

		ret = append(ret[:10], other)
	}
	return
}

func ImportRepoKey(base64Key string) (retKey string, err error) {
	util.PushMsg(Conf.Language(136), 3000)

	retKey = gulu.Str.RemoveInvisible(base64Key)
	retKey = strings.TrimSpace(retKey)
	if 1 > len(retKey) {
		err = errors.New(Conf.Language(142))
		return
	}

	key, err := base64.StdEncoding.DecodeString(retKey)
	if err != nil {
		logging.LogErrorf("import data repo key failed: %s", err)
		return "", errors.New(Conf.Language(157))
	}
	if 32 != len(key) {
		return "", errors.New(Conf.Language(157))
	}

	suspendLANSyncManager()
	Conf.Repo.Key = key
	Conf.Save()
	logging.LogInfof("imported repo key [%x]", sha1.Sum(Conf.Repo.Key))

	if err = os.RemoveAll(Conf.Repo.GetSaveDir()); err != nil {
		return
	}
	if err = os.MkdirAll(Conf.Repo.GetSaveDir(), 0755); err != nil {
		return
	}

	initDataRepo()

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Re-copy the exported key exactly; it must be standard base64 with no internal whitespace.
  2. If the key is URL-safe base64, convert it to standard (map - -> +, _ -> /) before importing.
  3. If only a passphrase is available, use InitRepoKeyFromPassphrase instead of ImportRepoKey.
Defensive patterns

Strategy: validation

Validate before calling

decoded, err := base64.StdEncoding.DecodeString(cleaned)
if err != nil {
    // try URL-safe base64 as a courtesy
    decoded, err = base64.URLEncoding.DecodeString(cleaned)
    if err != nil {
        return "", errors.New(model.Conf.Language(157))
    }
}

Prevention

When it happens

Trigger: Pasting a key that is not valid standard base64 — e.g. URL-safe base64, hex, a password mistaken for a key, trailing/inserted spaces inside the string, or copy/paste truncation introducing an invalid char.

Common situations: User confuses the passphrase with the exported key; key copied from a source that altered characters; URL-safe base64 (- and _) instead of standard (+ and /).

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/95a4bb2d75b69aa5. Report an issue: GitHub.