fix(加密解密): 修正加密用户名处理逻辑
build.yaml / build (push) Successful in 42s

This commit is contained in:
xiaoqidun committed 2026-09-30 01:55:44 +08:00
1 parent 4de22f9be7
commit 418a2fa0a7
4 files changed
+5 -14

No files matched your search

+1 -2
View File
@@ -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 ? "请重新选择加密方式" : "";
+1 -1
View File
@@ -65,7 +65,7 @@ type EncryptionRecipient struct {
}
// EncryptionOptions 设置GM/T0099加密,口令与证书方案二选一
// UserName标记口令接收者,不参与口令派生,留空使用User
// UserName标记口令接收者,不参与口令派生,留空不写入用户名
// 口令方案应使用足够长的随机口令;标准密钥派生不提供慢速口令哈希
type EncryptionOptions struct {
Password []byte
+1 -5
View File
@@ -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 {
+2 -6
View File
@@ -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 {