From 418a2fa0a741ce07a69b2ce1e8659dd6b903b1b2 Mon Sep 17 00:00:00 2001 From: xiaoqidun Date: Wed, 30 Sep 2026 01:55:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=8A=A0=E5=AF=86=E8=A7=A3=E5=AF=86):=20?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8A=A0=E5=AF=86=E7=94=A8=E6=88=B7=E5=90=8D?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/webui/ofdgo.js | 3 +-- ofdgo_crypto.go | 2 +- ofdgo_crypto_editor.go | 6 +----- ofdgo_crypto_package.go | 8 ++------ 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/assets/webui/ofdgo.js b/assets/webui/ofdgo.js index 66d39c3..d2b2fd0 100644 --- a/assets/webui/ofdgo.js +++ b/assets/webui/ofdgo.js @@ -4463,8 +4463,7 @@ function updateEncryptionType() { el.encryptionCertificatesRow.hidden = !certificates; el.encryptionPassword.required = el.encryptionConfirm.required = password; el.encryptionCertificates.required = certificates; - const user = mode === "password" && encryptionMode() === mode ? state.doc.encryption.users?.[0] || "" : ""; - el.encryptionUser.value = user === "User" ? "" : user; + el.encryptionUser.value = mode === "password" && encryptionMode() === mode ? state.doc.encryption.users?.[0] || "" : ""; el.encryptionPassword.value = el.encryptionConfirm.value = ""; el.encryptionCertificates.value = ""; el.encryptionStatus.textContent = mode === "keep" && state.doc?.encryption?.policyRequired ? "请重新选择加密方式" : ""; diff --git a/ofdgo_crypto.go b/ofdgo_crypto.go index 6a7f003..87c51cb 100644 --- a/ofdgo_crypto.go +++ b/ofdgo_crypto.go @@ -65,7 +65,7 @@ type EncryptionRecipient struct { } // EncryptionOptions 设置GM/T0099加密,口令与证书方案二选一 -// UserName标记口令接收者,不参与口令派生,留空使用User +// UserName标记口令接收者,不参与口令派生,留空不写入用户名 // 口令方案应使用足够长的随机口令;标准密钥派生不提供慢速口令哈希 type EncryptionOptions struct { Password []byte diff --git a/ofdgo_crypto_editor.go b/ofdgo_crypto_editor.go index 43c8384..a1e56af 100644 --- a/ofdgo_crypto_editor.go +++ b/ofdgo_crypto_editor.go @@ -40,11 +40,7 @@ func (e *Editor) SetEncryption(options *EncryptionOptions) error { } info := EncryptionInfo{Encrypted: true, Method: "1.1.1", Layers: 1} if len(options.Password) != 0 { - name := options.UserName - if name == "" { - name = "User" - } - info.Users = []string{name} + info.Users = []string{options.UserName} } else { info.Method = "1.1.2" for _, recipient := range options.Recipients { diff --git a/ofdgo_crypto_package.go b/ofdgo_crypto_package.go index c32216a..e94537a 100644 --- a/ofdgo_crypto_package.go +++ b/ofdgo_crypto_package.go @@ -67,7 +67,7 @@ type encryptionParams struct { // encryptionUser 保存单个接收者的公开信息及包装密钥 type encryptionUser struct { - Name string `xml:"UserName,attr"` + Name string `xml:"UserName,attr,omitempty"` Role string `xml:"UserType,attr,omitempty"` Certificate string `xml:"UserCert,omitempty"` Key string `xml:"EncryptedWK"` @@ -453,11 +453,7 @@ func encryptPackageParts(parts map[string][]byte, options EncryptionOptions, pro if err != nil { return nil, err } - name := options.UserName - if name == "" { - name = "User" - } - seed.Users = []encryptionUser{{Name: name, Role: options.UserType, Key: base64.StdEncoding.EncodeToString(wrapped), IV: base64.StdEncoding.EncodeToString(iv)}} + seed.Users = []encryptionUser{{Name: options.UserName, Role: options.UserType, Key: base64.StdEncoding.EncodeToString(wrapped), IV: base64.StdEncoding.EncodeToString(iv)}} } else { seed.Method = "1.1.2" for _, recipient := range options.Recipients {