@buka/nestjs-kit 3.0.1 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/README.md +2 -0
- package/dist/index.d.mts +18604 -259
- package/dist/index.d.ts +18604 -259
- package/dist/index.js +10090 -2497
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9770 -2429
- package/dist/index.mjs.map +1 -1
- package/docs/blind-index.md +107 -0
- package/docs/core/converters.md +409 -0
- package/docs/core/index.md +331 -0
- package/docs/core/models.md +303 -0
- package/docs/core/urn.md +214 -0
- package/docs/envelope-encryption.md +197 -0
- package/docs/exception.md +390 -0
- package/docs/index.md +89 -0
- package/docs/logger.md +289 -0
- package/docs/mikro-orm.md +471 -0
- package/docs/object-storage.md +193 -0
- package/docs/open-bao.md +168 -0
- package/docs/salted-hash.md +130 -0
- package/docs/swagger-patcher.md +60 -0
- package/package.json +52 -39
- package/.czrc +0 -3
- package/.vscode/tasks.json +0 -21
- package/coverage/cobertura-coverage.xml +0 -1173
- package/eslint.config.mjs +0 -18
- package/jest.config.cts +0 -23
- package/pnpm-workspace.yaml +0 -4
package/docs/core/urn.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# Urn — 统一资源名称
|
|
2
|
+
|
|
3
|
+
## 概述
|
|
4
|
+
|
|
5
|
+
`Urn` 是公司级统一资源名称(Uniform Resource Name)工具类,用于在系统间以标准化格式标识任意资源。无需注册模块,直接从主入口导入即可使用。
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import {
|
|
9
|
+
Urn,
|
|
10
|
+
NamespaceUrn,
|
|
11
|
+
ResourceUrn,
|
|
12
|
+
IdentifierUrn,
|
|
13
|
+
} from "@buka/nestjs-kit";
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## URN 格式
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
urn:buka:<namespace>[:<resource>[:<identifier>]]
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
| 层级 | 含义 | 规则 |
|
|
23
|
+
| ------------ | ----------------------------- | ------------------------------------------------ |
|
|
24
|
+
| `buka` | 组织前缀 | 固定值 |
|
|
25
|
+
| `namespace` | 资源类型所有者(概念域/平台) | 小写 kebab-case,如 `galaxy`、`infra` |
|
|
26
|
+
| `resource` | 资源类型 | 小写 kebab-case,如 `principal`、`oauth2-client` |
|
|
27
|
+
| `identifier` | 资源唯一标识 | UUID、hex 或其他自定义格式 |
|
|
28
|
+
|
|
29
|
+
### 三种粒度
|
|
30
|
+
|
|
31
|
+
URN 支持三种粒度,`resource` 和 `identifier` 均为可选:
|
|
32
|
+
|
|
33
|
+
| 粒度 | 类型 | 格式 | 示例 | 用途 |
|
|
34
|
+
| ------------ | --------------- | ------------------------------- | ---------------------------------------- | ---------------------------------- |
|
|
35
|
+
| namespace 级 | `NamespaceUrn` | `urn:buka:<ns>` | `urn:buka:galaxy` | 标识平台/系统整体,如 JWT audience |
|
|
36
|
+
| 资源类型级 | `ResourceUrn` | `urn:buka:<ns>:<resource>` | `urn:buka:galaxy:principal` | 标识一类资源 |
|
|
37
|
+
| 实例级 | `IdentifierUrn` | `urn:buka:<ns>:<resource>:<id>` | `urn:buka:galaxy:principal:550e8400-...` | 标识具体资源实例,如 JWT subject |
|
|
38
|
+
|
|
39
|
+
### namespace 划分原则
|
|
40
|
+
|
|
41
|
+
namespace 按**资源类型的定义权归属**划分,而非按部署单元。一个 namespace 可以有多个服务实现。
|
|
42
|
+
|
|
43
|
+
例如,`principal` 和 `oauth2-client` 都由 Galaxy 平台定义,因此都属于 `galaxy` namespace,即使它们可能由不同的微服务管理。
|
|
44
|
+
|
|
45
|
+
## API
|
|
46
|
+
|
|
47
|
+
### Urn.of
|
|
48
|
+
|
|
49
|
+
根据参数数量创建对应层级的 URN,返回类型在编译期自动窄化。构造函数为 `private`,`Urn.of` 是创建 URN 的主要入口。
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
static of(namespace: string): NamespaceUrn
|
|
53
|
+
static of(namespace: string, resource: string): ResourceUrn
|
|
54
|
+
static of(namespace: string, resource: string, identifier: string): IdentifierUrn
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
Urn.of("galaxy"); // → NamespaceUrn
|
|
59
|
+
Urn.of("galaxy", "principal"); // → ResourceUrn
|
|
60
|
+
Urn.of("galaxy", "principal", "550e8400-e29b-41d4-a716-..."); // → IdentifierUrn
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Urn.parse
|
|
64
|
+
|
|
65
|
+
从 URN 字符串解析为 `Urn` 实例。格式不合法时抛出 `Error`。返回宽类型 `Urn`,可通过类型守卫进一步窄化。
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
static parse(urn: string): Urn
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
const urn = Urn.parse("urn:buka:galaxy:principal:abc-123");
|
|
73
|
+
urn.namespace; // → 'galaxy'
|
|
74
|
+
urn.resource; // → 'principal'
|
|
75
|
+
urn.identifier; // → 'abc-123'
|
|
76
|
+
|
|
77
|
+
const nsUrn = Urn.parse("urn:buka:galaxy");
|
|
78
|
+
nsUrn.namespace; // → 'galaxy'
|
|
79
|
+
nsUrn.resource; // → undefined
|
|
80
|
+
nsUrn.identifier; // → undefined
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
> 格式不合法时抛出 `Error: Invalid URN: <input>`。
|
|
84
|
+
|
|
85
|
+
### toString
|
|
86
|
+
|
|
87
|
+
序列化为 URN 字符串。
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
toString(): string
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
Urn.of("galaxy", "principal", "abc-123").toString();
|
|
95
|
+
// → 'urn:buka:galaxy:principal:abc-123'
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### is
|
|
99
|
+
|
|
100
|
+
判断当前 URN 是否匹配指定条件。仅比较传入的参数,未传入的参数不参与比较。
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
is(namespace: string, resource?: string, identifier?: string): boolean
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
const urn = Urn.parse("urn:buka:galaxy:principal:abc-123");
|
|
108
|
+
|
|
109
|
+
urn.is("galaxy"); // → true(仅匹配 namespace)
|
|
110
|
+
urn.is("galaxy", "principal"); // → true
|
|
111
|
+
urn.is("galaxy", "principal", "abc-123"); // → true
|
|
112
|
+
urn.is("galaxy", "oauth2-client"); // → false
|
|
113
|
+
urn.is("infra"); // → false
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### withResource
|
|
117
|
+
|
|
118
|
+
从 `NamespaceUrn` 衍生出 `ResourceUrn`。当前 URN 已有 `resource` 时抛出 `Error`。
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
withResource(resource: string): ResourceUrn // 仅 NamespaceUrn 可调用
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
const ns = Urn.of("galaxy"); // NamespaceUrn
|
|
126
|
+
const resource = ns.withResource("principal"); // ResourceUrn
|
|
127
|
+
|
|
128
|
+
resource.withResource("other"); // ❌ 编译错误:ResourceUrn 上此方法为 never
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### withIdentifier
|
|
132
|
+
|
|
133
|
+
从 `ResourceUrn` 衍生出 `IdentifierUrn`。当前 URN 无 `resource` 或已有 `identifier` 时抛出 `Error`。
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
withIdentifier(identifier: string): IdentifierUrn // 仅 ResourceUrn 可调用
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
const resource = Urn.of("galaxy", "principal");
|
|
141
|
+
const instance = resource.withIdentifier("550e8400-..."); // IdentifierUrn
|
|
142
|
+
|
|
143
|
+
Urn.of("galaxy").withIdentifier("id"); // ❌ 编译错误:NamespaceUrn 上此方法为 never
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### 类型守卫
|
|
147
|
+
|
|
148
|
+
用于 `Urn.parse()` 返回的宽类型 `Urn` 的层级窄化:
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
isNamespaceUrn(): this is NamespaceUrn
|
|
152
|
+
isResourceUrn(): this is ResourceUrn
|
|
153
|
+
isIdentifierUrn(): this is IdentifierUrn
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
const urn = Urn.parse(token.sub);
|
|
158
|
+
|
|
159
|
+
if (urn.isResourceUrn()) {
|
|
160
|
+
urn.withIdentifier("some-id"); // ✅ 窄化后合法
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (urn.isIdentifierUrn()) {
|
|
164
|
+
const id = urn.identifier; // ✅ 类型为 string(非 string | undefined)
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## 使用场景
|
|
169
|
+
|
|
170
|
+
### JWT subject / audience
|
|
171
|
+
|
|
172
|
+
将 URN 用于 JWT 的 `sub` 和 `aud` 字段,使 token 自带主体类型信息:
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
// 签发 token
|
|
176
|
+
const accessToken = await sessionService.signAccessToken({
|
|
177
|
+
subject: Urn.of("galaxy", "principal", principal.id).toString(),
|
|
178
|
+
claims: {
|
|
179
|
+
aud: Urn.of("galaxy").toString(),
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// 消费 token —— 从 sub 中提取 principal ID
|
|
184
|
+
const subjectUrn = Urn.parse(payload.sub);
|
|
185
|
+
if (subjectUrn.isIdentifierUrn() && subjectUrn.is("galaxy", "principal")) {
|
|
186
|
+
const principalId = subjectUrn.identifier; // string,无需可选链
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### 资源类型判断
|
|
191
|
+
|
|
192
|
+
在不引入额外字段的情况下,通过 URN 判断资源类型并执行分支逻辑:
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
const urn = Urn.parse(session.subject);
|
|
196
|
+
|
|
197
|
+
if (urn.is("galaxy", "principal")) {
|
|
198
|
+
// 处理 Principal 类型的 subject
|
|
199
|
+
} else if (urn.is("galaxy", "oauth2-client")) {
|
|
200
|
+
// 处理 OAuth2 Client 类型的 subject
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### 派生方法逐层构建
|
|
205
|
+
|
|
206
|
+
当需要在运行时动态组装 URN 时,可通过派生方法链式构建:
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
const principalType = Urn.of("galaxy").withResource("principal"); // ResourceUrn,可复用
|
|
210
|
+
|
|
211
|
+
// 为不同 ID 生成实例级 URN
|
|
212
|
+
const urn1 = principalType.withIdentifier(id1);
|
|
213
|
+
const urn2 = principalType.withIdentifier(id2);
|
|
214
|
+
```
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# EnvelopeEncryptionModule — 信封加密模块
|
|
2
|
+
|
|
3
|
+
## 概述
|
|
4
|
+
|
|
5
|
+
`EnvelopeEncryptionModule` 实现了信封加密(Envelope Encryption)策略,采用 KEK/DEK 两层加密架构:
|
|
6
|
+
|
|
7
|
+
1. **DEK(Data Encryption Key)**:数据加密密钥,用于加密实际数据,每次加密生成新的 DEK
|
|
8
|
+
2. **KEK(Key Encryption Key)**:密钥加密密钥,由 OpenBao Transit 引擎管理,用于加密 DEK,永远不会离开 OpenBao
|
|
9
|
+
|
|
10
|
+
这种架构确保了即使数据库被泄露,攻击者也无法解密数据,因为 DEK 本身是加密的,而解密 DEK 需要 KEK(由 OpenBao 管理)。
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import {
|
|
14
|
+
EnvelopeEncryptionModule,
|
|
15
|
+
EnvelopeEncryptionService,
|
|
16
|
+
KeyEnvelope,
|
|
17
|
+
EncryptedPayload,
|
|
18
|
+
} from '@buka/nestjs-kit'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 模块配置
|
|
22
|
+
|
|
23
|
+
> `EnvelopeEncryptionModule` 依赖 `OpenBaoModule`,必须先注册 `OpenBaoModule`。
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { Module } from '@nestjs/common'
|
|
27
|
+
import { OpenBaoModule, EnvelopeEncryptionModule } from '@buka/nestjs-kit'
|
|
28
|
+
|
|
29
|
+
@Module({
|
|
30
|
+
imports: [
|
|
31
|
+
OpenBaoModule.register({
|
|
32
|
+
address: 'http://localhost:8200',
|
|
33
|
+
auth: { method: 'token', token: 's.xxxxx' },
|
|
34
|
+
}),
|
|
35
|
+
EnvelopeEncryptionModule.register({
|
|
36
|
+
version: 1,
|
|
37
|
+
}),
|
|
38
|
+
],
|
|
39
|
+
})
|
|
40
|
+
export class AppModule {}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 配置选项
|
|
44
|
+
|
|
45
|
+
| 选项 | 类型 | 必填 | 默认值 | 说明 |
|
|
46
|
+
|------|------|------|--------|------|
|
|
47
|
+
| `version` | `1` | 否 | `1` | 默认加密算法版本 |
|
|
48
|
+
|
|
49
|
+
## EnvelopeEncryptionService
|
|
50
|
+
|
|
51
|
+
核心加密服务,提供 `encrypt`、`decrypt`、`decryptToString` 和 `reencrypt` 方法。
|
|
52
|
+
|
|
53
|
+
### encrypt
|
|
54
|
+
|
|
55
|
+
加密数据,返回密钥信封和加密载荷。支持字符串和 Buffer 两种输入。
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
// 加密字符串
|
|
59
|
+
const [envelope, payload] = await encryptionService.encrypt({
|
|
60
|
+
kekId: 'user-secrets',
|
|
61
|
+
plaintext: '敏感数据',
|
|
62
|
+
encoding: 'utf8', // 可选,默认 'utf8'
|
|
63
|
+
extraAad: { userId: '123' }, // 可选,额外的 AAD
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
// 加密 Buffer
|
|
67
|
+
const [envelope, payload] = await encryptionService.encrypt({
|
|
68
|
+
kekId: 'user-secrets',
|
|
69
|
+
plaintext: Buffer.from([0x01, 0x02, 0x03]),
|
|
70
|
+
extraAad: { userId: '123' },
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### decrypt
|
|
75
|
+
|
|
76
|
+
解密数据,返回 `Buffer`。
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
const plaintext: Buffer = await encryptionService.decrypt({
|
|
80
|
+
envelope,
|
|
81
|
+
payload,
|
|
82
|
+
extraAad: { userId: '123' }, // 必须与加密时一致
|
|
83
|
+
})
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### decryptToString
|
|
87
|
+
|
|
88
|
+
解密为 UTF-8 字符串。
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
const text: string = await encryptionService.decryptToString({
|
|
92
|
+
envelope,
|
|
93
|
+
payload,
|
|
94
|
+
extraAad: { userId: '123' },
|
|
95
|
+
})
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### reencrypt
|
|
99
|
+
|
|
100
|
+
使用新的 KEK 重新加密数据,用于密钥轮换场景。
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
const [newEnvelope, newPayload] = await encryptionService.reencrypt({
|
|
104
|
+
envelope,
|
|
105
|
+
payload,
|
|
106
|
+
keyId: 'new-kek-id',
|
|
107
|
+
extraAad: { userId: '123' },
|
|
108
|
+
})
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Command 对象
|
|
112
|
+
|
|
113
|
+
### EncryptCommand
|
|
114
|
+
|
|
115
|
+
`EncryptCommand` 为 `EncryptStringCommand | EncryptBufferCommand` 的联合类型:
|
|
116
|
+
|
|
117
|
+
| 字段 | 类型 | 必填 | 说明 |
|
|
118
|
+
|------|------|------|------|
|
|
119
|
+
| `kekId` | `string` | 是 | KEK 标识符 |
|
|
120
|
+
| `plaintext` | `string \| Buffer` | 是 | 明文数据 |
|
|
121
|
+
| `encoding` | `BufferEncoding` | 否 | 字符编码(仅字符串模式),默认 `'utf8'` |
|
|
122
|
+
| `extraAad` | `Record<string, unknown>` | 否 | 额外的附加认证数据 |
|
|
123
|
+
|
|
124
|
+
### DecryptCommand
|
|
125
|
+
|
|
126
|
+
| 字段 | 类型 | 必填 | 说明 |
|
|
127
|
+
|------|------|------|------|
|
|
128
|
+
| `envelope` | `KeyEnvelope` | 是 | 密钥信封实体 |
|
|
129
|
+
| `payload` | `EncryptedPayload` | 是 | 加密数据实体 |
|
|
130
|
+
| `extraAad` | `Record<string, unknown>` | 否 | 额外的附加认证数据(必须与加密时一致) |
|
|
131
|
+
|
|
132
|
+
### ReencryptCommand
|
|
133
|
+
|
|
134
|
+
继承 `DecryptCommand` 的所有字段,额外增加:
|
|
135
|
+
|
|
136
|
+
| 字段 | 类型 | 必填 | 说明 |
|
|
137
|
+
|------|------|------|------|
|
|
138
|
+
| `keyId` | `string` | 是 | 新的 KEK ID |
|
|
139
|
+
|
|
140
|
+
## 可嵌入实体
|
|
141
|
+
|
|
142
|
+
### KeyEnvelope
|
|
143
|
+
|
|
144
|
+
密钥信封的 MikroORM 嵌入式实体,包含 KEK 相关元数据。所有字段标记为 `hidden`,不会被序列化到 API 响应。
|
|
145
|
+
|
|
146
|
+
| 字段 | 类型 | 说明 |
|
|
147
|
+
|------|------|------|
|
|
148
|
+
| `kekId` | `varchar(64)` | KEK 标识符,用于 AAD 绑定 |
|
|
149
|
+
| `kekVersion` | `smallint` | KEK 版本号,用于密钥轮换追踪 |
|
|
150
|
+
| `dek` | `bytea` | 加密的 DEK(由 KEK 加密) |
|
|
151
|
+
|
|
152
|
+
### EncryptedPayload
|
|
153
|
+
|
|
154
|
+
加密数据的 MikroORM 嵌入式实体。所有字段标记为 `hidden`。
|
|
155
|
+
|
|
156
|
+
| 字段 | 类型 | 说明 |
|
|
157
|
+
|------|------|------|
|
|
158
|
+
| `ciphertext` | `bytea` | 加密后的数据 |
|
|
159
|
+
| `cipherIv` | `bytea` | 初始化向量 |
|
|
160
|
+
| `cipherTag` | `bytea` | GCM 认证标签 |
|
|
161
|
+
| `cipherVersion` | `smallint` | 加密算法版本号,默认 `1` |
|
|
162
|
+
|
|
163
|
+
### 在实体中使用
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
import { Entity } from '@mikro-orm/core'
|
|
167
|
+
import { DiscreteEntity, Column } from '@buka/nestjs-kit/mikro-orm'
|
|
168
|
+
import { KeyEnvelope, EncryptedPayload } from '@buka/nestjs-kit'
|
|
169
|
+
|
|
170
|
+
@Entity()
|
|
171
|
+
export class UserSecretEntity extends DiscreteEntity {
|
|
172
|
+
@Column.Embedded(() => KeyEnvelope)
|
|
173
|
+
envelope!: KeyEnvelope
|
|
174
|
+
|
|
175
|
+
@Column.Embedded(() => EncryptedPayload)
|
|
176
|
+
payload!: EncryptedPayload
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## 加密细节
|
|
181
|
+
|
|
182
|
+
### V1 实现:AES-256-GCM
|
|
183
|
+
|
|
184
|
+
- **算法**:`aes-256-gcm`
|
|
185
|
+
- **DEK 生成**:通过 OpenBao Transit 引擎的 `datakey` API 生成 256 位密钥
|
|
186
|
+
- **IV**:12 字节随机数(`crypto.randomBytes(12)`)
|
|
187
|
+
- **认证标签**:16 字节
|
|
188
|
+
- **AAD 绑定**:将 `kekId` 和 `extraAad` 通过 stable JSON 序列化后编码到 AAD 中,确保密文与 kekId 绑定,防止密文替换攻击
|
|
189
|
+
- **内存安全**:加密/解密完成后立即清零内存中的 DEK(`dek.fill(0)`)
|
|
190
|
+
|
|
191
|
+
## 注意事项
|
|
192
|
+
|
|
193
|
+
> `extraAad` 在加密和解密时必须完全一致,否则 GCM 认证将失败并抛出异常。可以利用此特性将密文绑定到特定的业务上下文(如用户 ID)。
|
|
194
|
+
|
|
195
|
+
> KEK 永远不会离开 OpenBao,所有 DEK 的加密/解密操作均通过 OpenBao Transit API 完成。
|
|
196
|
+
|
|
197
|
+
> 解密时会根据 `EncryptedPayload.cipherVersion` 自动选择对应版本的 Cipher 实现,确保向后兼容。
|