hexo-blog-encrypt 4.1.0 → 4.2.0

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/ReadMe.zh.md CHANGED
@@ -1,353 +1,79 @@
1
1
  # hexo-blog-encrypt
2
2
 
3
- > 为单篇 Hexo 文章设置密码. 构建时使用 AES-256-GCM 加密, 读者在浏览器中通过
4
- > Web Crypto API 解密. 无需服务端, 生成的 HTML 中不含明文.
3
+ 在静态 Hexo 博客上发布文章,用密码分享正文。Hexo 在构建时加密,读者在浏览器中解锁。无需注册账号,也不需要解密服务器。
5
4
 
6
- **[▶ 在线演示](https://d0n9x1n.github.io/hexo-blog-encrypt/)**: 所有演示密码都是 `hello`.
5
+ **[体验一篇加密文章](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/card/)**(演示密码:`hello`) · [入门指南](https://github.com/D0n9X1n/hexo-blog-encrypt/wiki/Getting-Started-zh-CN) · [English](https://github.com/D0n9X1n/hexo-blog-encrypt/blob/master/ReadMe.md)
7
6
 
8
- [![GitHub release](https://img.shields.io/github/v/release/D0n9X1n/hexo-blog-encrypt?include_prereleases&logo=github&label=release&color=brightgreen)](https://github.com/D0n9X1n/hexo-blog-encrypt/releases)
9
- [![npm](https://img.shields.io/npm/v/hexo-blog-encrypt?logo=npm&color=brightgreen)](https://www.npmjs.com/package/hexo-blog-encrypt)
10
- [![npm downloads](https://img.shields.io/npm/dm/hexo-blog-encrypt?logo=npm&label=downloads)](https://www.npmjs.com/package/hexo-blog-encrypt)
11
- [![License](https://img.shields.io/npm/l/hexo-blog-encrypt?color=brightgreen)](./LICENSE)
12
- [![Tests](https://github.com/D0n9X1n/hexo-blog-encrypt/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/D0n9X1n/hexo-blog-encrypt/actions/workflows/test.yml)
13
- [![Coverage](https://img.shields.io/badge/server%20coverage-100%25-brightgreen)](./docs/DEVELOPMENT.md)
14
- [![Live Demo](https://img.shields.io/badge/demo-online-brightgreen?logo=github)](https://d0n9x1n.github.io/hexo-blog-encrypt/)
15
- [![Node](https://img.shields.io/node/v/hexo-blog-encrypt?logo=node.js&color=brightgreen)](./package.json)
16
- [![Hexo](https://img.shields.io/npm/dependency-version/hexo-blog-encrypt/peer/hexo?logo=hexo&label=hexo)](https://hexo.io/)
17
- [![Dependencies](https://img.shields.io/badge/runtime%20dependencies-0-brightgreen)](./package.json)
18
- [![npm provenance](https://img.shields.io/badge/npm-provenance-blue?logo=npm)](https://www.npmjs.com/package/hexo-blog-encrypt#provenance)
19
- [![GitHub stars](https://img.shields.io/github/stars/D0n9X1n/hexo-blog-encrypt?style=flat&logo=github)](https://github.com/D0n9X1n/hexo-blog-encrypt/stargazers)
7
+ [![左侧为 Card 主题的密码框,右侧为输入正确密码后显示的文章摘录](https://raw.githubusercontent.com/D0n9X1n/hexo-blog-encrypt/master/assets/readme/unlock.webp)](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/card/)
20
8
 
21
- [English](./ReadMe.md) · 中文说明 · [Wiki](https://github.com/D0n9X1n/hexo-blog-encrypt/wiki) · [Releases](https://github.com/D0n9X1n/hexo-blog-encrypt/releases)
9
+ [![发布版本](https://img.shields.io/github/v/release/D0n9X1n/hexo-blog-encrypt)](https://github.com/D0n9X1n/hexo-blog-encrypt/releases)
10
+ [![npm](https://img.shields.io/npm/v/hexo-blog-encrypt)](https://www.npmjs.com/package/hexo-blog-encrypt)
11
+ [![许可证](https://img.shields.io/npm/l/hexo-blog-encrypt)](https://github.com/D0n9X1n/hexo-blog-encrypt/blob/master/LICENSE)
12
+ [![测试](https://github.com/D0n9X1n/hexo-blog-encrypt/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/D0n9X1n/hexo-blog-encrypt/actions/workflows/test.yml)
13
+ [![在线演示](https://img.shields.io/badge/demo-online-brightgreen)](https://d0n9x1n.github.io/hexo-blog-encrypt/)
22
14
 
23
- ## 目录
15
+ ## 给第一篇文章加密
24
16
 
25
- - [主要特性](#主要特性)
26
- - [在线演示](#在线演示)
27
- - [安装](#安装)
28
- - [快速开始](#快速开始)
29
- - [配置](#配置)
30
- - [主题集成](#主题集成)
31
- - [浏览器支持](#浏览器支持)
32
- - [为什么要从 v3 升级](#为什么要从-v3-升级)
33
- - [从 v3 升级](#从-v3-升级)
34
- - [参与贡献](#参与贡献)
35
- - [许可](#许可)
17
+ 在 Hexo 站点目录下安装插件(需要 Node.js 18+、Hexo 5+):
36
18
 
37
- ## 主要特性
38
-
39
- | | |
40
- | --- | --- |
41
- | **认证加密** | [PBKDF2](https://www.rfc-editor.org/rfc/rfc8018)-SHA256 派生密钥, [AES-256-GCM](https://csrc.nist.gov/pubs/sp/800/38/d/final) 加密. GCM 认证标签会拒绝错误密码和被篡改的密文. |
42
- | **只用原生密码学 API** | 构建时使用 Node.js [`crypto`](https://nodejs.org/api/crypto.html), 阅读时使用浏览器 [Web Crypto API](https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Crypto_API). 没有运行时依赖. |
43
- | **每篇文章独立密钥** | 每篇文章都有独立的 32 字节 salt 和 12 字节 nonce, 破解一篇不会加速对其它文章的攻击. |
44
- | **文章密码或标签密码** | 在文章信息头写 `password:`, 或在 `_config.yml` 中为标签配置密码. |
45
- | **8 个主题** | `default`, `blink`, `flip`, `shrink`, `surge`, `up`, `wave`, `xray`. 放入一个 HTML 文件即可新增主题. |
46
- | **脚本照常运行** | 解密后文章中的脚本按文档顺序执行. 文章显示后触发 `hexo-blog-decrypt` 事件. |
47
- | **默认保护隐私** | 除非用 `autoSave` 开启, 否则不保存密码或密钥. |
48
- | **完整测试** | 服务端 100% 行 / 分支 / 函数覆盖, 并用 Playwright 对每个主题做端到端测试. |
49
-
50
- ## 在线演示
51
-
52
- 打开 **[演示站点](https://d0n9x1n.github.io/hexo-blog-encrypt/)**, 所有密码都是 `hello`.
53
-
54
- - [主题展示](https://d0n9x1n.github.io/hexo-blog-encrypt/tags/theme-demo/)
55
- - [解密回调](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/callback/)
56
- - [脚本加载顺序与缓存密钥](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/script-order/)
57
-
58
- ## 安装
59
-
60
- ```bash
19
+ ```sh
61
20
  npm install --save hexo-blog-encrypt
62
21
  ```
63
22
 
64
- 需要 Node.js 18 及以上, Hexo 5 及以上. npm 包带有
65
- [provenance](https://docs.npmjs.com/generating-provenance-statements) 证明,
66
- 并镜像发布到 GitHub Packages (`@d0n9x1n/hexo-blog-encrypt`).
67
-
68
- ## 快速开始
69
-
70
- 在文章信息头中加入 `password`:
71
-
72
- ```markdown
73
- ---
74
- title: Hello World
75
- date: 2016-03-30 21:18:02
76
- password: hello
77
- ---
78
- ```
79
-
80
- 然后重新生成并预览:
81
-
82
- ```bash
83
- hexo clean && hexo generate && hexo server
84
- ```
85
-
86
- 文章正文会被替换为密码输入框. 首页等列表页显示 `abstract` 文本, 而不是正文.
87
-
88
- ## 配置
89
-
90
- 配置按以下顺序生效:
91
-
92
- **文章信息头 > `_config.yml` 中的 `encrypt:` > 内置默认值**
93
-
94
- 文章信息头中的 `password` 优先于标签密码.
95
-
96
- ### 文章信息头
97
-
98
- ```markdown
99
- ---
100
- title: Hello World
101
- tags:
102
- - 作为日记加密
103
- date: 2016-03-30 21:12:21
104
- password: mikemessi
105
- abstract: 有东西被加密了, 请输入密码查看.
106
- message: 您好, 这里需要密码.
107
- wrong_pass_message: 抱歉, 这个密码看着不太对, 请再试试.
108
- theme: xray
109
- ---
110
- ```
111
-
112
- ### 全站 `_config.yml`
23
+ 在**一篇文章**的文件头中设置密码。请为自己的文章选择足够长且不重复的口令,不要使用演示密码。
113
24
 
114
25
  ```yaml
115
- encrypt: # hexo-blog-encrypt
116
- abstract: 有东西被加密了, 请输入密码查看.
117
- message: 您好, 这里需要密码.
118
- wrong_pass_message: 抱歉, 这个密码看着不太对, 请再试试.
119
- theme: default
120
- silent: false
121
-
122
- # 加密所有带有以下标签的文章.
123
- tags:
124
- - {name: 作为日记加密, password: 密码A}
125
- - {name: 作为提示加密, password: 密码B}
126
-
127
- # 在密码框旁显示 "解密" 按钮. 默认: true.
128
- decryptButton:
129
- show: true
130
- text: 解密
131
-
132
- # 将派生出的 AES 密钥缓存到 localStorage, 刷新页面时跳过密码输入.
133
- # 默认: false. 可在这里全局开启, 也可在文章信息头中单独开启.
134
- # 缓存键为 `hbe.v4.<页面路径>`.
135
- autoSave: false
136
-
137
- # 让同一篇文章的 PBKDF2 salt 在 clean build 之间保持稳定, 文章身份来自
138
- # post permalink. 默认: false. 配合 autoSave 时, 适用于
139
- # Cloudflare Pages、Vercel、Netlify、GitHub Actions 等每次部署都会从
140
- # 干净环境重新生成 HTML 的平台.
141
- #
142
- # 只稳定 salt; AES-GCM nonce 每次加密仍然随机, 避免 nonce reuse.
143
- # 如果文章 permalink 改变, stable salt 也会改变, 该页面已有的
144
- # localStorage 缓存会失效.
145
- stableSalt: false
146
-
147
- # PBKDF2 迭代次数. 下限: 100_000. 推荐 ≥ 600_000
148
- # (OWASP 2023 关于 PBKDF2-SHA256 的推荐). 低于推荐值时构建会打印 warning.
149
- # 默认: 250_000.
150
- kdf:
151
- iterations: 250000
152
- ```
153
-
154
- `autoSave` 读取缓存密钥时会比较缓存中的 salt 与当前页面 salt. 仅 nonce
155
- 变化不会提前删除缓存; 浏览器会使用缓存密钥配合当前页面的 nonce 与密文尝试
156
- 解密. 如果 AES-GCM 认证失败, 该缓存条目会被清除, 访客需要重新输入密码.
157
-
158
- **已保存的密钥及其暴露面.** 保存的密钥位于 `localStorage` 的
159
- `hbe.v4.<页面路径>`, 在被删除前可在本设备上解锁该文章. 同源运行的任何脚本
160
- (主题、统计、评论组件或被注入的脚本) 都能读取它, 因此只有在信任站点上所有脚本时
161
- 才开启 `autoSave`. 文章通过已保存的密钥显示后, 上方的 **忘记已保存的密钥**
162
- 按钮可删除该条目. 对某篇文章关闭 `autoSave` 后, 下次访问时会删除该文章已保存的
163
- 密钥; v3 遗留的 `hexo-blog-encrypt:#…` 条目会被自动清除.
164
-
165
- ### 配置项一览
166
-
167
- | 配置项 | 默认值 | 说明 |
168
- | --- | --- | --- |
169
- | `password` | 无 | 加密该文章. `""` 表示不加密, 包括不使用标签加密. 匹配到的标签条目若没有密码, 构建会失败. |
170
- | `password: { env: NAME }` | 无 | 构建时从环境变量 `NAME` 读取密码 (可用于文章信息头、`encrypt.password` 或 `encrypt.tags[].password`). 变量缺失或为空时构建失败; 密码值不会被打印或渲染. 这只能让密码不出现在配置文件中, 不能保护公开提交的明文 Markdown. |
171
- | `abstract` | `Here's something encrypted…` | 首页和归档页显示的摘要. |
172
- | `message` | `Hey, password is required here.` | 密码输入框的提示文字. |
173
- | `wrong_pass_message` | `Oh, this is an invalid password…` | 密码错误时的行内提示. |
174
- | `theme` | `default` | 8 个内置主题之一. 未知名称会回退到 `default` 并打印 warning. |
175
- | `tags` | `[]` | 仅限 `_config.yml`. 标签加密使用的 `{name, password}` 列表. |
176
- | `decryptButton.show` / `.text` | `true` / `Decrypt` | 是否显示解密按钮及其文字. |
177
- | `autoSave` | `false` | 将派生密钥缓存到 `localStorage`. |
178
- | `stableSalt` | `false` | 由 permalink 派生 salt, 让缓存密钥在 clean build 后仍然有效. |
179
- | `kdf.iterations` | `250000` | PBKDF2 迭代次数, 必须是不小于 100,000 的整数. |
180
- | `silent` | `false` | 隐藏构建时的 info 日志. warning 和 error 仍会输出. |
181
- | `wrong_hash_message` | `wrong_pass_message` | 已废弃的别名. AES-GCM 对错误密码和篡改给出同样的结果. |
182
- | `template` | 无 | `theme` 的已废弃别名. |
183
-
184
- 布尔配置项 (`autoSave`、`stableSalt`、`silent`、`decryptButton.show`) 必须是 `true` 或 `false`. 带引号的 `"true"`/`"false"` 会被接受并打印 warning; 其他值会使构建失败.
185
-
186
- `abstract`、`message`、`wrong_pass_message` 和 `decryptButton.text` 的默认值跟随文章的 `lang`/`language`, 否则跟随站点 `language`. `zh`、`zh-CN` 和 `zh-Hans` 使用简体中文, 其他语言使用英文. 显式配置始终优先.
187
-
188
- ### 对单篇文章禁用标签加密
189
-
190
- 在该文章的信息头中设置空密码:
191
-
192
- ```markdown
193
26
  ---
194
- title: 带有加密标签的公开文章
195
- tags:
196
- - A Tag should be encrypted
197
- password: ""
27
+ title: 旅行手记
28
+ theme: wave
29
+ password: { env: POST_PASSWORD }
30
+ abstract: 这次旅行的记录。想读正文,可以向我索取密码。
198
31
  ---
199
32
  ```
200
33
 
201
- ## 主题集成
34
+ 在构建环境中设置 `POST_PASSWORD`,然后运行 `npx hexo clean && npx hexo generate && npx hexo server`。打开文章,输入口令,按 **Enter** 解锁。正式站点请使用 **HTTPS**。要一次为多篇文章加密,可使用[标签规则](https://github.com/D0n9X1n/hexo-blog-encrypt/wiki/Tag-Based-Encryption-zh-CN)。
202
35
 
203
- ### 解密后事件
36
+ **哪些内容仍然公开?** 标题、摘要,以及你另外发布的 Markdown 源文件或原始媒体都不会因此保密。请勿把私密源文件提交到公开仓库。访客可以下载密文后离线猜测密码;若需要按账号限制访问,请使用具备访问控制的托管服务。[了解安全模型 →](https://github.com/D0n9X1n/hexo-blog-encrypt/wiki/Security-Model-zh-CN)
204
37
 
205
- 每篇文章显示后, 插件会在 `window` 上触发一次 `hexo-blog-decrypt`.
206
- `event.detail.mode` 为 `manual` (输入密码) 或 `cached` (已缓存的密钥),
207
- `event.detail.element` 是显示出的容器 (首页同时展示多篇加密文章时可用来区分).
208
- 监听它来重新执行需要扫描正文的代码:
38
+ ## 选择喜欢的样式
209
39
 
210
- ```js
211
- window.addEventListener('hexo-blog-decrypt', function (event) {
212
- // 重新初始化主题的目录、代码高亮等.
213
- console.log('Decrypted:', event.detail.mode, event.detail.element);
214
- });
215
- ```
216
-
217
- ### PJAX 与单页应用主题
218
-
219
- 脚本会初始化页面上的每一篇加密文章, 且每篇只初始化一次. 在 `document` 上触发
220
- `pjax:complete`, `pjax:success`, `swup:contentReplaced` 或 `turbo:load` 时会自动
221
- 重新扫描. 其他路由方案可在替换内容后调用幂等的初始化函数:
222
-
223
- ```js
224
- window.hexoBlogEncrypt.init(); // 整个文档
225
- window.hexoBlogEncrypt.init(container); // 仅某个子树
226
- ```
227
-
228
- ### 加密文章中的脚本
229
-
230
- 文章中的脚本会在解密后执行. 自 **4.0.3** 起, 普通外部脚本会按文档顺序加载,
231
- 再执行其后的内联脚本, 因此 DPlayer 等依赖库的代码可以正确初始化. 解密事件会等待
232
- 恢复的外部脚本加载完成、加载失败或达到 **每个脚本 15 秒** 的期限. 超时不会取消
233
- 脚本, 它之后仍可能执行. 原有的 `onload` / `onerror` 处理函数会被保留. 显式
234
- `async` 的脚本仍独立加载, 恢复的 `defer` 脚本不会重建文档解析阶段. 内联
235
- `type="module"` 脚本及脚本中的异步任务保留原生调度, 可能在解密事件之后才完成.
236
-
237
- ```markdown
238
- <script>
239
- // 文章解密后执行.
240
- console.log('Hello from an encrypted post');
241
- </script>
242
- ```
243
-
244
- ### 目录 (TOC)
245
-
246
- **不要把加密文章的 `post.origin` 渲染到生成的 HTML 中.** 它保存的是为旧版 Hexo
247
- 集成保留的明文. 用 `display:none` 隐藏的 TOC 仍然会公开标题. 搜索、订阅和站点地图
248
- 插件也必须排除加密文章的明文字段.
249
-
250
- 只为未加密文章生成服务端 TOC:
251
-
252
- ```ejs
253
- <% if (post.toc === true && !post.encrypt) { %>
254
- <div class="toc-article"><%- toc(post.content, {list_number: true}) %></div>
255
- <% } %>
256
- <%- post.content %>
257
- ```
258
-
259
- 对加密文章, 在 `hexo-blog-decrypt` 回调中根据解密后的 `#hexo-blog-encrypt`
260
- 内容在浏览器端生成目录.
261
-
262
- ### 加密主题
263
-
264
- 通过文章信息头的 `theme:` 为单篇文章选择主题, 或在 `_config.yml` 中为全站设置.
265
- 在线预览:
266
-
267
- [default](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/default/) ·
268
- [blink](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/blink/) ·
269
- [flip](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/flip/) ·
270
- [shrink](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/shrink/) ·
271
- [surge](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/surge/) ·
272
- [up](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/up/) ·
273
- [wave](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/wave/) ·
274
- [xray](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/xray/)
275
-
276
- 新增主题请参阅 [docs/THEMES.md](./docs/THEMES.md).
277
-
278
- ## 浏览器支持
279
-
280
- 解密使用 Web Crypto (`crypto.subtle`), 需要 **安全上下文**: HTTPS 或
281
- `http://localhost`.
282
-
283
- | 浏览器 | 最低版本 | 测试方式 |
284
- | --- | --- | --- |
285
- | Chromium / Edge | 92+ | 自动: CI 中 Playwright Chromium, Hexo 7 与 8 |
286
- | Firefox | 90+ | 自动: CI 中 Playwright Firefox |
287
- | Safari (macOS) | 14+ | 自动: CI 中 Playwright WebKit (WebKit 引擎, 非 Safari 本身) |
288
- | Safari (iOS) | 14+ | 仅手动测试 |
289
-
290
- 最低版本依据 Web Crypto 与语言特性支持; CI 运行的是当前的 Playwright
291
- 浏览器版本, 而非这些最低版本.
40
+ | [Wave](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/wave/) | [Terminal](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/terminal/) |
41
+ | --- | --- |
42
+ | [![Wave 主题:密码框获得焦点时,一道弧形下划线从右向左滑过](https://raw.githubusercontent.com/D0n9X1n/hexo-blog-encrypt/master/assets/readme/wave.webp)](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/wave/) | [![Terminal 主题:深色密码框搭配等宽文字和命令行提示符](https://raw.githubusercontent.com/D0n9X1n/hexo-blog-encrypt/master/assets/readme/terminal.webp)](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/terminal/) |
292
43
 
293
- 在非 localhost 的纯 HTTP 站点上, `crypto.subtle` 为 `undefined`, 无法解密;
294
- 文章会提示 "请通过 HTTPS 打开此页面", 而不是显示密码错误.
295
- 生产环境请始终使用 HTTPS.
44
+ 可以在单篇文章或全站配置里设置 `theme:`。11 种样式使用相同的加密方式;八个经典主题保留各自获得焦点和填入密码时的交互效果。
296
45
 
297
- ## 为什么要从 v3 升级
46
+ **经典:** [default](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/default/) · [blink](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/blink/) · [flip](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/flip/) · [shrink](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/shrink/) · [surge](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/surge/) · [up](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/up/) · [wave](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/wave/) · [xray](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/xray/)
298
47
 
299
- v4 修复了 v3 真实存在的安全短板与体验问题:
48
+ **现代:** [minimal](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/minimal/) · [card](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/card/) · [terminal](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/terminal/)
300
49
 
301
- - **更强的密码学.** **AES-256-GCM** 自带认证标签, 取代了 v3 的 AES-CBC 加独立
302
- HMAC: 单一原语、单一认证路径, 不存在 CBC padding-oracle 或 HMAC 比较漏洞.
303
- - **每篇独立 salt 和 nonce.** v3 所有文章共用同一个 salt, 同一个密码到处派生出
304
- 同一个密钥. v4 每篇独立派生密钥, 攻击者无法在使用相同密码的文章间复用 PBKDF2
305
- 计算.
306
- - **更强的 KDF 默认值.** v3 仅使用 **1,024** 轮 PBKDF2-SHA256. v4 默认
307
- **250,000** 轮 (每次猜测约 240 倍工作量), 推荐 600,000 轮以上 (OWASP 2023).
308
- 可通过 `kdf.iterations` 按文章调整.
309
- - **默认保护隐私.** v3 总是把解密内容缓存到 `localStorage`, 之后使用该设备的人
310
- 可以再次阅读. v4 默认 `autoSave: false`, 按文章或全局开启.
311
- - **行内错误提示.** v3 在密码错误时弹出 `window.alert()`. v4 在输入框旁显示错误
312
- (`role="alert"`).
313
- - **可选的解密按钮**, 方便不知道按 Enter 提交的读者.
314
- - **更小的体积.** 移除了 CryptoJS, 浏览器端 bundle 约 6 KB (minified).
315
- - **完整测试.** 每次推送都运行 100% 服务端覆盖测试及覆盖全部 8 个主题的
316
- Playwright 测试.
50
+ ## 发布前须知
317
51
 
318
- 每项变化的详细原因见 wiki:
319
- [Migration v3 → v4](https://github.com/D0n9X1n/hexo-blog-encrypt/wiki/Migration-v3-to-v4).
52
+ 插件 **v4.2.0** 写入格式 5,仍可读取格式 4 的旧文章。加密使用 scrypt 和 AES-256-GCM,不依赖其他 npm 运行时包。读者需要通过 HTTPS 或 localhost 访问。密钥缓存**默认关闭**,共享设备请保持关闭。
320
53
 
321
- ## 从 v3 升级
54
+ <details>
55
+ <summary><strong>密码、密钥缓存与重新构建</strong></summary>
322
56
 
323
- v4 修改了加密格式 (AES-GCM, 每篇独立 salt 和 nonce). v4 无法读取 v3 的产物,
324
- 反之亦然.
57
+ | 文章文件头 | 作用 |
58
+ | --- | --- |
59
+ | `password: { env: NAME }` | 从构建环境读取密码,也可用于 `encrypt.tags[].password`。变量缺失或为空时,构建会失败。 |
60
+ | `password: ""` | 即使标签匹配加密规则,这篇文章也保持公开。 |
325
61
 
326
- 1. 升级插件: `npm install --save hexo-blog-encrypt@^4`.
327
- 2. 从源文件重新生成: `hexo clean && hexo generate`.
328
- 3. 如果使用 CDN, 请清空缓存. 每次加密都使用新的 nonce, 因此每次构建文章 HTML
329
- 都会变化. 运行时资源 `lib/hbe.<hash>.js` 按内容 hash 命名, 只有 bundle
330
- 改变时才会变化.
331
- 4. 可选: 从配置和文章信息头中删除 `wrong_hash_message`. 它在 v4 中已废弃,
332
- 将在 v5 中删除.
62
+ `autoSave` 将不可导出的 CryptoKey 保存在 IndexedDB 中,不保存密码:格式 5 使用 HKDF 基础密钥,格式 4 使用 AES-GCM 密钥。升级会清除旧版保存的原始密钥,读者可能需要重新输入一次密码。同源代码仍可使用缓存的密钥。读者可点击“忘记已保存的密钥”;`window.hexoBlogEncrypt.forget(target?)` 只有在存储事务完成后才确认删除成功。
333
63
 
334
- 不会修改任何源 `.md` 文件. 完整的不兼容变更列表见 [v4.0.0 发布说明](https://github.com/D0n9X1n/hexo-blog-encrypt/releases/tag/v4.0.0) 和 [Releases](https://github.com/D0n9X1n/hexo-blog-encrypt/releases).
64
+ `stableSalt` 和 `autoSave` 默认关闭。在 Cloudflare Pages、Vercel、Netlify 或 GitHub Actions 上,`stableSalt: true` 可让缓存跨干净构建继续生效。permalink 改变后,旧缓存失效。每次加密仍使用随机 nonce。承诺值不匹配或 AES-GCM 认证失败时,浏览器会清除缓存。
335
65
 
336
- ## 参与贡献
66
+ </details>
337
67
 
338
- 欢迎提交 issue 和 pull request. 请先阅读
339
- [CONTRIBUTING.md](./.github/CONTRIBUTING.md). 报告 bug 时请附上复现步骤、日志和
340
- 配置, 信息不完整的 issue 可能会被关闭.
68
+ <details>
69
+ <summary><strong>加密、资源完整性与主题集成</strong></summary>
341
70
 
342
- - [架构](./docs/ARCHITECTURE.md)
343
- - [开发](./docs/DEVELOPMENT.md)
344
- - [发布](./docs/RELEASING.md)
345
- - [主题](./docs/THEMES.md)
71
+ 默认使用 `scrypt`(`N=32768, r=8, p=3`);也可选择 `pbkdf2-sha256`(600000 次迭代)或 `pbkdf2-sha512`(220000 次迭代)。HKDF-SHA256 为每个信封分别派生加密密钥和承诺值。旧版脚本无法读取新文章:请一起部署 HTML、`css/hbe.<hex10>.css` 和 `lib/hbe.<hex10>.js`。SHA-384 校验针对实际输出的字节,前提是 HTML 可信。
346
72
 
347
- ## 许可
73
+ 监听 `hexo-blog-decrypt` 可在解锁后重建目录或重新渲染 MathJax。不要从私密明文生成公开的目录、订阅或搜索索引。[加密文章目录指南](https://github.com/D0n9X1n/hexo-blog-encrypt/wiki/Encrypted-TOC-zh-CN)介绍了 `hexo-encrypt-toc` skill。普通外部脚本按文档顺序加载,每个最多等待 15 秒;`async` 脚本和内联 `type="module"` 保留浏览器的原生调度。[体验脚本加载顺序](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/script-order/)。
348
74
 
349
- [MIT](./LICENSE)
75
+ </details>
350
76
 
351
- ## 感谢
77
+ **[浏览中文 Wiki](https://github.com/D0n9X1n/hexo-blog-encrypt/wiki/Home-zh-CN)** · [配置参考](https://github.com/D0n9X1n/hexo-blog-encrypt/wiki/Configuration-Reference-zh-CN) · [编写主题](https://github.com/D0n9X1n/hexo-blog-encrypt/wiki/Theme-Authoring-zh-CN) · [故障排查](https://github.com/D0n9X1n/hexo-blog-encrypt/wiki/Troubleshooting-zh-CN)
352
78
 
353
- 协作者: [xiazeyu](https://github.com/xiazeyu)
79
+ [参与贡献](https://github.com/D0n9X1n/hexo-blog-encrypt/blob/master/.github/CONTRIBUTING.md) · [私下报告安全漏洞](https://github.com/D0n9X1n/hexo-blog-encrypt/blob/master/SECURITY.md) · [MIT 许可证](https://github.com/D0n9X1n/hexo-blog-encrypt/blob/master/LICENSE) · 感谢 [xiazeyu](https://github.com/xiazeyu)。
@@ -11,14 +11,15 @@
11
11
  </script>
12
12
  <div class="hbe hbe-content">
13
13
  <form id="hbeForm" class="hbe hbe-form">
14
- <div class="hbe hbe-input hbe-input-blink">
15
- <input class="hbe hbe-input-field hbe-input-field-blink" type="password" id="hbePass">
16
- <label class="hbe hbe-input-label hbe-input-label-blink" for="hbePass">
17
- <span class="hbe hbe-input-label-content hbe-input-label-content-blink" data-content="{{hbeMessage}}">{{hbeMessage}}</span>
18
- </label>
19
- </div>
20
- <button class="hbe hbe-button{{hbeButtonClass}}" type="submit">{{hbeButtonText}}</button>
21
- <div class="hbe hbe-error" role="alert" aria-live="polite"></div>
14
+ <div class="hbe hbe-input hbe-input-blink hbe-classic">
15
+ <input class="hbe hbe-input-field hbe-input-field-blink" type="password" id="hbePass">
16
+ <label class="hbe hbe-input-label hbe-input-label-blink" for="hbePass">
17
+ <span class="hbe hbe-input-label-content hbe-input-label-content-blink">{{hbeMessage}}</span>
18
+ <span class="hbe-roll" aria-hidden="true">{{hbeMessage}}</span>
19
+ </label>
20
+ </div>
21
+ <button class="hbe hbe-button{{hbeButtonClass}}" type="submit"><span class="hbe hbe-button-text">{{hbeButtonText}}</span></button>
22
+ <div class="hbe hbe-error" role="alert"></div>
22
23
  </form>
23
24
  </div>
24
25
  </div>
package/lib/hbe.bundle.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";(()=>{var y=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(n){throw t=0,n}};var E=y((Ee,x)=>{"use strict";function w(e){return e.querySelector("#hbeForm,.hbe-form,form")}function M(e){return e.querySelector('#hbePass,.hbe-input-field,input[type="password"]')}var K=0;function N(e,t){if(!t)return;let n=t.id;if(n&&document.getElementById(n)===t)return;let r;do r=(n||"hbePass")+"-"+ ++K;while(document.getElementById(r));let o=e.querySelectorAll("label");for(let c=0;c<o.length;c++)n&&o[c].htmlFor===n&&(o[c].htmlFor=r);t.id=r}function R(e,t,n){if(e){e.setAttribute("aria-busy",n?"true":"false");let r=e.querySelector(".hbe-button");r&&(r.disabled=!!n)}t&&(t.disabled=!!n)}function q(e){if(!e)return;let t=e.closest(".hbe-input")||e.parentNode,n=()=>t.classList.toggle("hbe-input--filled",e.value!=="");e.addEventListener("input",n),e.addEventListener("change",n),n()}function G(e){e&&(e.focus(),e.select())}function W(e,t){let n=e.querySelector('[role="alert"]');if(!n){n=document.createElement("div"),n.setAttribute("role","alert"),n.className="hbe hbe-error";let r=w(e);r?r.parentNode.insertBefore(n,r.nextSibling):e.appendChild(n)}n.textContent=t}function U(e){let t=e.querySelector('[role="alert"]');t&&(t.textContent="")}function Y(e,t){e&&e.addEventListener("submit",n=>{n.preventDefault(),t()})}function V(e,t,n){let r=document.createElement("div");r.className="hbe hbe-forget";let o=document.createElement("button");o.type="button",o.className="hbe hbe-forget-button",o.textContent=t.forget;let c=document.createElement("span");c.setAttribute("role","status"),c.tabIndex=-1,o.addEventListener("click",()=>{n(),r.removeChild(o),c.textContent=t.forgotten,c.focus()}),r.appendChild(o),r.appendChild(c),e.parentNode.insertBefore(r,e)}x.exports={findForm:w,findInput:M,ensureUniqueId:N,setBusy:R,trackFilled:q,refocus:G,showError:W,clearError:U,attachSubmit:Y,addForgetButton:V}});var A=y((ve,S)=>{"use strict";var j=new TextDecoder("utf-8",{fatal:!0}),X=new TextEncoder;function d(e){let t=e.length;if(t%2!==0)throw new Error("hexo-blog-encrypt: hex string has odd length");let n=new Uint8Array(t/2);for(let r=0;r<n.length;r++)n[r]=parseInt(e.substr(r*2,2),16);return n}async function v(e,t,n){let r=await crypto.subtle.importKey("raw",X.encode(e),{name:"PBKDF2"},!1,["deriveKey"]);return crypto.subtle.deriveKey({name:"PBKDF2",salt:t,iterations:n,hash:"SHA-256"},r,{name:"AES-GCM",length:256},!0,["decrypt"])}async function h(e,t,n){let r=await crypto.subtle.decrypt({name:"AES-GCM",iv:t,tagLength:128},e,n);return j.decode(r)}async function z({password:e,saltHex:t,nonceHex:n,ciphertextHex:r,iterations:o}){try{let c=d(t),i=d(n),u=d(r);if(u.length<16)return{ok:!1};let s=await v(e,c,o);return{ok:!0,plaintext:await h(s,i,u),key:s}}catch(c){return{ok:!1}}}async function J({key:e,nonceHex:t,ciphertextHex:n}){try{let r=d(t),o=d(n);return o.length<16?{ok:!1}:{ok:!0,plaintext:await h(e,r,o)}}catch(r){return{ok:!1}}}S.exports={tryDecryptWithPassword:z,tryDecryptWithKey:J,deriveKey:v,decryptWithKey:h,hexToBytes:d}});var _=y((Se,C)=>{"use strict";var $=/^(?:application|text)\/(?:x-)?(?:java|ecma)script$|^text\/(?:javascript1\.[0-5]|jscript|livescript)$/i;function T(e){let t=document.createElement("script");for(let n of e.attributes)t.setAttribute(n.name,n.value);return e.nonce&&(t.nonce=e.nonce),t.text=e.text,t}function I(e){let t=document.createElement("div");return t.innerHTML=e,t}function Q(e){let t=e.getAttribute("type");if(t===null){let o=e.getAttribute("language");t=o?"text/"+o:""}let n=t.toLowerCase();if(n==="module")return"module";if(n==="importmap"||n==="speculationrules")return"declarative";let r=t.replace(/^[\t\n\f\r ]+|[\t\n\f\r ]+$/g,"");return t===""||$.test(r)?"classic":"data"}function Z(e,t,n){return n?new Promise(r=>{let o=()=>{clearTimeout(c),t.removeEventListener("load",o),t.removeEventListener("error",o),r()},c=setTimeout(()=>{console.warn("hexo-blog-encrypt: timed out waiting for a decrypted script to load."),o()},15e3);t.addEventListener("load",o),t.addEventListener("error",o),e.parentNode.replaceChild(t,e)}):(e.parentNode.replaceChild(t,e),Promise.resolve())}async function ee(e){let t=[],n="noModule"in document.createElement("script");for(let r of e.querySelectorAll("script")){if(!e.contains(r))continue;let o=Q(r);if(o==="data"||o==="classic"&&r.noModule&&n||o==="module"&&!n)continue;let c=T(r),i=o!=="declarative"&&c.hasAttribute("src"),u=i&&c.hasAttribute("async");o==="classic"&&i&&!u&&(c.async=!1);let s=Z(r,c,i);u?t.push(s):await s}await Promise.all(t)}async function te(e,t){let n=I(t);return n.id="hexo-blog-encrypt",n.classList.add("hbe","hbe-decrypted-content"),e.parentNode.replaceChild(n,e),await ee(n),n}C.exports={getExecutableScript:T,convertHTMLToElement:I,swapInDecryptedDOM:te}});var L=y((Ae,H)=>{"use strict";var B="hbe.v4.";function p(e){return B+e}function ne(e){let t="";for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}function re(e){let t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n}async function oe({id:e,key:t,saltHex:n,nonceHex:r,autoSave:o}){if(o)try{let c=await crypto.subtle.exportKey("raw",t),i={version:4,dk:ne(new Uint8Array(c)),salt:n,nonce:r};localStorage.setItem(p(e),JSON.stringify(i))}catch(c){}}async function ce({id:e,expectedSaltHex:t}){let n;try{let r=localStorage.getItem(p(e));if(!r)return null;n=JSON.parse(r)}catch(r){return null}if(!n||n.version!==4||typeof n.dk!="string"||typeof n.salt!="string"||typeof n.nonce!="string"||"hmk"in n||"hmacDigest"in n){try{localStorage.removeItem(p(e))}catch(r){}return null}if(n.salt!==t){try{localStorage.removeItem(p(e))}catch(r){}return null}try{let r=re(n.dk);return await crypto.subtle.importKey("raw",r,{name:"AES-GCM"},!0,["decrypt"])}catch(r){try{localStorage.removeItem(p(e))}catch(o){}return null}}function ae(e){try{localStorage.removeItem(p(e))}catch(t){}}var se="hexo-blog-encrypt:#";function ie(){try{for(let e=localStorage.length-1;e>=0;e--){let t=localStorage.key(e);t&&t.indexOf(se)===0&&localStorage.removeItem(t)}}catch(e){}}H.exports={save:oe,load:ce,clear:ae,purgeLegacy:ie,STORAGE_KEY_PREFIX:B,SCHEMA_VERSION:4}});var O=y((Te,D)=>{"use strict";var k={en:{incompatible:"hexo-blog-encrypt: this page was built with an incompatible plugin version. Rebuild the site after upgrading the plugin.",noCrypto:"hexo-blog-encrypt: this browser cannot decrypt here because Web Crypto is unavailable. Open the page over HTTPS (or localhost) in an up-to-date browser.",forget:"Forget saved key",forgotten:"Saved key forgotten."},zh:{incompatible:"hexo-blog-encrypt: \u6B64\u9875\u9762\u7531\u63D2\u4EF6\u7248\u672C\u4E0D\u517C\u5BB9\u7684\u6784\u5EFA\u751F\u6210. \u5347\u7EA7\u63D2\u4EF6\u540E\u8BF7\u91CD\u65B0\u6784\u5EFA\u7AD9\u70B9.",noCrypto:"hexo-blog-encrypt: Web Crypto \u4E0D\u53EF\u7528, \u5F53\u524D\u6D4F\u89C8\u5668\u65E0\u6CD5\u5728\u6B64\u89E3\u5BC6. \u8BF7\u901A\u8FC7 HTTPS (\u6216 localhost) \u4F7F\u7528\u6700\u65B0\u7248\u6D4F\u89C8\u5668\u6253\u5F00\u6B64\u9875\u9762.",forget:"\u5FD8\u8BB0\u5DF2\u4FDD\u5B58\u7684\u5BC6\u94A5",forgotten:"\u5DF2\u5FD8\u8BB0\u4FDD\u5B58\u7684\u5BC6\u94A5."}};function le(){return(document.documentElement.getAttribute("lang")||"").toLowerCase().indexOf("zh")===0?k.zh:k.en}D.exports={messages:le}});var a=E(),P=A(),ue=_(),f=L(),de=O(),pe="4",fe=25e4,m="[data-hbe-format],.hbe-container,#hexo-blog-encrypt",F="__hbeInit";function ye(){return!!(window.isSecureContext&&window.crypto&&window.crypto.subtle)}function he(e){let t=e.dataset,n=e.querySelector('script#hbeData,script[type="hbeData"]');return{format:t.hbeFormat,wpm:t.wpm||"Wrong password.",whm:t.whm||t.wpm||"Wrong password.",saltHex:t.salt,nonceHex:t.nonce,iterations:parseInt(t.kdfIterations,10)||fe,autoSave:t.autoSave==="true",ciphertextHex:n?n.textContent.trim():""}}function me(e,t){try{window.dispatchEvent(new CustomEvent("hexo-blog-decrypt",{detail:{mode:e,element:t}}))}catch(n){try{window.dispatchEvent(new Event("hexo-blog-decrypt"))}catch(r){}}}function ge(e){let t=location.pathname+location.search,n=Array.prototype.indexOf.call(document.querySelectorAll(m),e);return n>0?t+"#"+n:t}function be(e){if(e[F]||e.classList.contains("hbe-decrypted-content"))return;e[F]=!0;let t=he(e),n=de.messages();if(t.format!==pe){a.showError(e,n.incompatible);return}let r=a.findForm(e),o=a.findInput(e);a.ensureUniqueId(e,o),a.trackFilled(o);let c=ge(e);if(t.autoSave||f.clear(c),!ye()){a.showError(e,n.noCrypto),a.attachSubmit(r,()=>a.showError(e,n.noCrypto));return}let i=!1,u=async(s,l)=>{if(i)return;i=!0;let b=await ue.swapInDecryptedDOM(e,s);l==="cached"&&a.addForgetButton(b,n,()=>f.clear(c)),me(l,b)};a.attachSubmit(r,async()=>{a.clearError(e);let s=o?o.value:"";if(!s){a.showError(e,t.wpm),a.refocus(o);return}a.setBusy(r,o,!0);let l;try{l=await P.tryDecryptWithPassword({password:s,saltHex:t.saltHex,nonceHex:t.nonceHex,ciphertextHex:t.ciphertextHex,iterations:t.iterations})}finally{a.setBusy(r,o,!1)}if(!l.ok){a.showError(e,t.wpm),a.refocus(o);return}t.autoSave&&await f.save({id:c,key:l.key,saltHex:t.saltHex,nonceHex:t.nonceHex,autoSave:!0}),await u(l.plaintext,"manual")}),we(t,c,u).then(s=>{let l=document.activeElement;!s&&!i&&o&&(!l||l===document.body)&&o.focus()})}async function we(e,t,n){if(!e.autoSave)return!1;let r=await f.load({id:t,expectedSaltHex:e.saltHex});if(!r)return!1;let o=await P.tryDecryptWithKey({key:r,nonceHex:e.nonceHex,ciphertextHex:e.ciphertextHex});return o.ok?(await n(o.plaintext,"cached"),!0):(f.clear(t),!1)}function g(e){e=e||document;let t=Array.prototype.slice.call(e.querySelectorAll(m));e.matches&&e.matches(m)&&t.unshift(e);for(let n=0;n<t.length;n++)be(t[n])}if(!window.hexoBlogEncrypt){window.hexoBlogEncrypt={init:g},f.purgeLegacy();let e=()=>window.hexoBlogEncrypt.init();["pjax:complete","pjax:success","swup:contentReplaced","turbo:load"].forEach(t=>{document.addEventListener(t,e)})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>g()):g();})();
1
+ "use strict";(()=>{var g=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(n){throw t=0,n}};var _=g((yt,O)=>{"use strict";function N(e){return e.querySelector("#hbeForm,.hbe-form,form")}function Ae(e){return e.querySelector('#hbePass,.hbe-input-field,input[type="password"]')}var ke=0;function Se(e,t){if(!t)return;let n=t.id;if(n&&document.getElementById(n)===t)return;let r;do r=(n||"hbePass")+"-"+ ++ke;while(document.getElementById(r));let o=e.querySelectorAll("label");for(let a=0;a<o.length;a++)n&&o[a].htmlFor===n&&(o[a].htmlFor=r);t.id=r}function De(e,t,n){if(e){let r=n?"true":"false";e.setAttribute("aria-busy",r);let o=e.querySelector(".hbe-button");o&&(o.setAttribute("aria-busy",r),o.disabled=!!n)}t&&(t.disabled=!!n)}function Ce(e){if(!e)return;let t={autocomplete:"current-password",spellcheck:"false",autocapitalize:"off",autocorrect:"off"};for(let o of Object.keys(t))e.hasAttribute(o)||e.setAttribute(o,t[o]);let n=e.closest(".hbe-input")||e.parentNode,r=()=>n.classList.toggle("hbe-input--filled",!!e.value);for(let o of["input","change"])e.addEventListener(o,r);e.form&&e.form.addEventListener("reset",()=>setTimeout(r)),r()}function Le(e){e&&(e.focus(),e.select())}function Te(e,t){let n=e.querySelector('[role="alert"]');if(!n){n=document.createElement("div"),n.setAttribute("role","alert"),n.className="hbe hbe-error";let r=N(e);r?r.parentNode.insertBefore(n,r.nextSibling):e.appendChild(n)}n.textContent=t}function Ue(e){let t=e.querySelector('[role="alert"]');t&&(t.textContent="")}function qe(e,t){e&&e.addEventListener("submit",n=>{n.preventDefault(),t()})}function Ie(e,t,n){let r=document.createElement("div");r.className="hbe hbe-forget";let o=document.createElement("button");o.type="button",o.className="hbe hbe-forget-button",o.textContent=t.forget;let a=document.createElement("span");a.setAttribute("role","status"),a.tabIndex=-1,o.addEventListener("click",async()=>{if(o.disabled=!0,!await n()){o.disabled=!1,o.focus();return}r.removeChild(o),a.textContent=t.forgotten,a.focus()}),r.appendChild(o),r.appendChild(a),e.parentNode.insertBefore(r,e)}O.exports={findForm:N,findInput:Ae,ensureUniqueId:Se,setBusy:De,trackFilled:Ce,refocus:Le,showError:Te,clearError:Ue,attachSubmit:qe,addForgetButton:Ie}});var V=g((ht,z)=>{"use strict";var j=()=>globalThis.crypto.subtle;function W(e){return j().importKey("raw",e.length?e:Uint8Array.of(0),{name:"HMAC",hash:"SHA-256"},!1,["sign"])}async function U(e,t,n){let r=new Uint8Array(t.length+4),o=new DataView(r.buffer),a=new Uint8Array(n);try{r.set(t);for(let s=0;s<n;s+=32){o.setUint32(t.length,1+s/32);let i=new Uint8Array(await j().sign("HMAC",e,r));try{a.set(i.subarray(0,Math.min(32,n-s)),s)}finally{i.fill(0)}}return a}catch(s){throw a.fill(0),s}finally{r.fill(0)}}var D=(e,t)=>e<<t|e>>>32-t;function v(e,t,n,r,o){e[n]^=D(e[t]+e[o],7),e[r]^=D(e[n]+e[t],9),e[o]^=D(e[r]+e[n],13),e[t]^=D(e[o]+e[r],18)}function R(e,t,n,r){let o=e.length/32;for(let a=0;a<16;a++)n[a]=e[e.length-16+a];for(let a=0;a<2*o;a++){for(let s=0;s<16;s++)n[s]^=e[a*16+s];r.set(n);for(let s=0;s<4;s++)v(r,0,4,8,12),v(r,5,9,13,1),v(r,10,14,2,6),v(r,15,3,7,11),v(r,0,1,2,3),v(r,5,6,7,4),v(r,10,11,8,9),v(r,15,12,13,14);for(let s=0;s<16;s++)n[s]+=r[s];t.set(n,16*((a>>1)+a%2*o))}}var Ke=()=>new Promise(e=>setTimeout(e,0));async function Fe(e,t,n,r,o,a,s=Ke){let i=[],l=u=>(i.push(u),u);try{let u=await W(e),p=l(await U(u,t,128*r*o)),h=new DataView(p.buffer),c=32*r,f=l(new Uint32Array(n*c)),A=l(new Uint32Array(2*c)),k=l(new Uint32Array(16)),ve=l(new Uint32Array(16)),w=A.subarray(0,c),L=A.subarray(c),B=0;for(let T=0;T<o;T++){let M=T*c;for(let y=0;y<c;y++)w[y]=h.getUint32(4*(M+y),!0);for(let y=0;y<2*n;y++){if(y<n)f.set(w,y*c);else{let Ee=(w[c-16]&n-1)*c;for(let S=0;S<c;S++)w[S]^=f[Ee+S]}R(w,L,k,ve);let xe=w;w=L,L=xe,++B%2048===0&&await s(B,i)}for(let y=0;y<c;y++)h.setUint32(4*(M+y),w[y],!0)}return await U(u,p,a)}finally{for(let u of i)u.fill(0)}}z.exports={hmacKey:W,blocks:U,mix:R,scrypt:Fe}});var I=g((mt,J)=>{"use strict";var q=["","pbkdf2-sha256","pbkdf2-sha512","scrypt"],x=(e,t,n)=>Number.isInteger(e)&&e>=t&&e<=n;function b(e,t){if(!e)throw new Error(t)}function G(e){let t=q.indexOf(e.algorithm);if(b(t>0,"unknown KDF"),t<3)b(x(e.iterations,1e5,1e7),"kdf.iterations must be an integer 100000\u201310000000");else{let{N:n,r,p:o}=e,a=Math.log2(n);b(x(n,8192,262144)&&Number.isInteger(a)&&x(r,1,32)&&x(o,1,16)&&a<16*r&&128*r*n<=128*2**20&&n*r*o<=2**20,"invalid scrypt cost")}return e}function X(e){G(e);let t=q.indexOf(e.algorithm),n=Uint8Array.of(72,66,69,53,5,t,1,1,0,0,0,0,0,0,0,0),r=new DataView(n.buffer);return t===3?(n[8]=Math.log2(e.N),r.setUint16(9,e.r),r.setUint16(11,e.p)):r.setUint32(8,e.iterations),n}function Pe(e){b(e.length===16,"header length");let t=new DataView(e.buffer,e.byteOffset,16),n=q[e[5]],r;return e[5]===3?(b(x(e[8],13,18),"scrypt log2N"),r={algorithm:n,N:2**e[8],r:t.getUint16(9),p:t.getUint16(11)}):r={algorithm:n,iterations:t.getUint32(8)},b(X(r).every((o,a)=>o===e[a]),"noncanonical header"),r}function $(e){b(x(e,0,2**24),"plaintext length");let t=e+4;if(t<=256)return 256;let n=31-Math.clz32(t),r=32-Math.clz32(n),o=(1<<n-r)-1;return t+o&~o}function He(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(0),n=$(t);return b(t<=e.length-4&&n===e.length,"frame length"),b(!e.subarray(4+t).some(r=>r!==0),"padding"),new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode(e.subarray(4,4+t))}J.exports={checkKdf:G,headerFor:X,readHeader:Pe,frameLength:$,unframe:He}});var ne=g((bt,te)=>{"use strict";var{scrypt:Be}=V(),{unframe:Me}=I(),Ne=new TextDecoder("utf-8",{fatal:!0}),Y=new TextEncoder,Q={name:"AES-GCM",length:256};async function Z({kdf:e,salt:t},n){if(e.algorithm==="scrypt")return Be(n,t,e.N,e.r,e.p,32);let r=await crypto.subtle.importKey("raw",n,"PBKDF2",!1,["deriveBits"]);return new Uint8Array(await crypto.subtle.deriveBits({name:"PBKDF2",hash:e.algorithm==="pbkdf2-sha256"?"SHA-256":"SHA-512",salt:t,iterations:e.iterations},r,256))}async function Oe(e,t){let n=await Z(e,t);try{return await crypto.subtle.importKey("raw",n,"HKDF",!1,["deriveKey","deriveBits"])}finally{n.fill(0)}}async function _e(e,t){let n=Y.encode(t);try{if(e.version==="5")return await Oe(e,n);let r=await crypto.subtle.importKey("raw",n,"PBKDF2",!1,["deriveKey"]);return await crypto.subtle.deriveKey({name:"PBKDF2",hash:"SHA-256",salt:e.salt,iterations:e.kdf.iterations},r,Q,!1,["decrypt"])}finally{n.fill(0)}}function je(e,t){let n=0;for(let r=0;r<32;r++)n|=e[r]^t[r];return n===0}async function We({blob:e,salt:t,nonce:n},r){let o=new Uint8Array(92),a=o.subarray(0,60);a.set(e.subarray(0,16)),a.set(t,16),a.set(n,48);let s=h=>({name:"HKDF",salt:a,hash:"SHA-256",info:Y.encode("hexo-blog-encrypt:v5:"+h)}),i=e.subarray(16,48),l=new Uint8Array(await crypto.subtle.deriveBits(s("cmt"),r,256));try{if(!je(l,i))throw Error("authentication")}finally{l.fill(0)}let u=await crypto.subtle.deriveKey(s("enc"),r,Q,!1,["decrypt"]);o.set(i,60);let p=new Uint8Array(await crypto.subtle.decrypt({name:"AES-GCM",iv:n,additionalData:o,tagLength:128},u,e.subarray(48)));try{return Me(p)}finally{p.fill(0)}}async function ee(e,t){if(e.version==="5")return We(e,t);let n=await crypto.subtle.decrypt({name:"AES-GCM",iv:e.nonce,tagLength:128},t,e.blob);return Ne.decode(n)}async function Re({wire:e,password:t}){try{let n=await _e(e,t);return{ok:!0,plaintext:await ee(e,n),key:n}}catch(n){return{ok:!1}}}async function ze({wire:e,key:t}){try{return{ok:!0,plaintext:await ee(e,t)}}catch(n){return{ok:!1}}}te.exports={tryDecryptWithPassword:Re,tryDecryptWithKey:ze,ikm:Z}});var se=g((wt,ae)=>{"use strict";var Ve=/^(?:application|text)\/(?:x-)?(?:java|ecma)script$|^text\/(?:javascript1\.[0-5]|jscript|livescript)$/i;function re(e){let t=document.createElement("script");for(let n of e.attributes)t.setAttribute(n.name,n.value);return e.nonce&&(t.nonce=e.nonce),t.text=e.text,t}function oe(e){let t=document.createElement("div");return t.innerHTML=e,t}function Ge(e){let t=e.getAttribute("type");if(t===null){let o=e.getAttribute("language");t=o?"text/"+o:""}let n=t.toLowerCase();if(n==="module")return"module";if(n==="importmap"||n==="speculationrules")return"declarative";let r=t.replace(/^[\t\n\f\r ]+|[\t\n\f\r ]+$/g,"");return t===""||Ve.test(r)?"classic":"data"}function Xe(e,t,n){return n?new Promise(r=>{let o=()=>{clearTimeout(a),t.removeEventListener("load",o),t.removeEventListener("error",o),r()},a=setTimeout(()=>{console.warn("hexo-blog-encrypt: timed out waiting for a decrypted script to load."),o()},15e3);t.addEventListener("load",o),t.addEventListener("error",o),e.parentNode.replaceChild(t,e)}):(e.parentNode.replaceChild(t,e),Promise.resolve())}async function $e(e){let t=[],n="noModule"in document.createElement("script");for(let r of e.querySelectorAll("script")){if(!e.contains(r))continue;let o=Ge(r);if(o==="data"||o==="classic"&&r.noModule&&n||o==="module"&&!n)continue;let a=re(r),s=o!=="declarative"&&a.hasAttribute("src"),i=s&&a.hasAttribute("async");o==="classic"&&s&&!i&&(a.async=!1);let l=Xe(r,a,s);i?t.push(l):await l}await Promise.all(t)}async function Je(e,t){let n=oe(t);return n.id="hexo-blog-encrypt",n.classList.add("hbe","hbe-decrypted-content"),e.parentNode.replaceChild(n,e),await $e(n),n}ae.exports={getExecutableScript:re,convertHTMLToElement:oe,swapInDecryptedDOM:Je}});var ue=g((gt,le)=>{"use strict";var ie=["id","version","salt","kdfKey"],K=e=>IDBKeyRange.bound([e],[e,[]]),ce=(e,t)=>{var n;return(t==null?void 0:t.extractable)===!1&&((n=t.algorithm)==null?void 0:n.name)===(e.version==="4"?"AES-GCM":"HKDF")};function F(e,t){return new Promise(n=>{let r,o=!1;try{r=indexedDB.open("hexo-blog-encrypt",1)}catch(a){n(e);return}r.onerror=r.onblocked=()=>{o=!0,n(e)},r.onupgradeneeded=()=>{let a=r.result;a.objectStoreNames.contains("keys")||a.createObjectStore("keys",{keyPath:ie})},r.onsuccess=()=>{let a=r.result;if(o){a.close();return}a.onversionchange=()=>a.close();let s=u=>{a.close(),n(u)},i,l=e;try{i=a.transaction("keys","readwrite"),i.oncomplete=()=>s(l),i.onabort=i.onerror=()=>s(e),t(i.objectStore("keys"),u=>{l=u})}catch(u){try{i==null||i.abort()}catch(p){}s(e)}}})}function Ye(e){return F(!1,(t,n)=>{t.delete(K(e)),n(!0)})}function Qe(e,t){if(!ce(e,t))return Promise.resolve(!1);let{id:n,version:r,salt:o,kdfKey:a}=e;return F(!1,(s,i)=>{s.delete(K(n)),s.put({id:n,version:r,salt:o,kdfKey:a,key:t}),i(!0)})}function Ze(e){return F(null,(t,n)=>{let r=t.get(ie.map(o=>e[o]));r.onsuccess=()=>{var a;let o=(a=r.result)==null?void 0:a.key;ce(e,o)?n(o):t.delete(K(e.id))}})}function et(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n&&(n.startsWith("hexo-blog-encrypt:#")||n.startsWith("hbe.v4."))&&e.push(n)}for(let t of e)localStorage.removeItem(t)}catch(e){}}le.exports={load:Ze,save:Qe,clear:Ye,purgeLegacy:et}});var pe=g((vt,de)=>{"use strict";var fe={en:{incompatible:"hexo-blog-encrypt: this page was built with an incompatible plugin version. Rebuild the site after upgrading the plugin.",noCrypto:"hexo-blog-encrypt: this browser cannot decrypt here because Web Crypto is unavailable. Open the page over HTTPS (or localhost) in an up-to-date browser.",forget:"Forget saved key",forgotten:"Saved key forgotten."},zh:{incompatible:"hexo-blog-encrypt: \u6B64\u9875\u9762\u7531\u63D2\u4EF6\u7248\u672C\u4E0D\u517C\u5BB9\u7684\u6784\u5EFA\u751F\u6210. \u5347\u7EA7\u63D2\u4EF6\u540E\u8BF7\u91CD\u65B0\u6784\u5EFA\u7AD9\u70B9.",noCrypto:"hexo-blog-encrypt: Web Crypto \u4E0D\u53EF\u7528, \u5F53\u524D\u6D4F\u89C8\u5668\u65E0\u6CD5\u5728\u6B64\u89E3\u5BC6. \u8BF7\u901A\u8FC7 HTTPS (\u6216 localhost) \u4F7F\u7528\u6700\u65B0\u7248\u6D4F\u89C8\u5668\u6253\u5F00\u6B64\u9875\u9762.",forget:"\u5FD8\u8BB0\u5DF2\u4FDD\u5B58\u7684\u5BC6\u94A5",forgotten:"\u5DF2\u5FD8\u8BB0\u4FDD\u5B58\u7684\u5BC6\u94A5."}};function tt(){return(document.documentElement.getAttribute("lang")||"").toLowerCase().indexOf("zh")===0?fe.zh:fe.en}de.exports={messages:tt}});var me=g((xt,he)=>{"use strict";var{readHeader:nt}=I(),P=/[^a-f\d]/i;function ye(e){return e>=640&&e<=34603136&&e%2===0}function rt(e){let t=new Uint8Array(e.length/2);for(let n=0;n<t.length;n++)t[n]=parseInt(e.slice(n*2,n*2+2),16);return t}function ot(e,t=rt){var n;try{let r=e.format;if(r!=="4"&&r!=="5")return{ok:!1};let{ciphertextHex:o,saltHex:a,nonceHex:s,iterations:i}=e;if(typeof o!="string")return{ok:!1};let l=o.trim(),u=l.length;if(r==="5"?!ye(u):u<32||u%2!==0)return{ok:!1};if(typeof a!="string"||a.length!==64||typeof s!="string"||s.length!==24)return{ok:!1};if(P.test(l)||P.test(a)||P.test(s))return{ok:!1};let p=r==="4"&&i===void 0?"250000":i;if(typeof p!="string"||/\D/.test(p))return{ok:!1};let h=Number(p);if(h<1)return{ok:!1};let c,f;if(r==="4"){if(h>2147483647)return{ok:!1};c={algorithm:"pbkdf2-sha256",iterations:h},f="pbkdf2-sha256:"+h}else{if(p[0]==="0")return{ok:!1};if(c=nt(t(l.slice(0,32))),h!==((n=c.N)!=null?n:c.iterations))return{ok:!1};f=(l.slice(10,12)+l.slice(16,32)).toLowerCase()}return{ok:!0,wire:{version:r,kdf:c,kdfKey:f,saltHex:a.toLowerCase(),salt:t(a),nonce:t(s),blob:t(l)}}}catch(r){return{ok:!1}}}he.exports={parseWire:ot,validSize:ye}});var d=_(),be=ne(),at=se(),m=ue(),st=pe(),{parseWire:it}=me(),E="[data-hbe-format],.hbe-container,#hexo-blog-encrypt",we="__hbeInit";function ct(){return!!(window.isSecureContext&&window.crypto&&window.crypto.subtle)}function lt(e){let t=e.dataset,n=e.querySelector(t.hbeFormat==="4"?'script#hbeData,script[type="hbeData"]':"script#hbeData");return{format:t.hbeFormat,wpm:t.wpm||"Wrong password.",saltHex:t.salt,nonceHex:t.nonce,iterations:t.kdfIterations,autoSave:t.autoSave==="true",ciphertextHex:n?n.textContent:""}}function ut(e,t){try{window.dispatchEvent(new CustomEvent("hexo-blog-decrypt",{detail:{mode:e,element:t}}))}catch(n){try{window.dispatchEvent(new Event("hexo-blog-decrypt"))}catch(r){}}}var ge=e=>Array.prototype.indexOf.call(document.querySelectorAll(E),e);function C(e=0){let t=location.pathname+location.search;return e>0?t+"#"+e:t}function ft(e){if(e==null||e==="")return m.clear(C());if(typeof e=="string")return m.clear(e);let t;try{if(!Node.prototype.contains.call(document,e))return Promise.resolve(!1);let r=o=>Element.prototype.closest.call(o,E)||Element.prototype.querySelector.call(o,E);if(e===document)t=Document.prototype.querySelector.call(document,E);else try{t=r(e)}catch(o){t=e.parentElement&&r(e.parentElement)}}catch(r){return Promise.resolve(!1)}if(!t)return m.clear(C());let n=ge(t);return n<0?Promise.resolve(!1):m.clear(C(n))}function dt(e){if(e[we]||e.classList.contains("hbe-decrypted-content"))return;e[we]=!0;let t=st.messages();if(e.dataset.hbeFormat!=="4"&&e.dataset.hbeFormat!=="5"){d.showError(e,t.incompatible);return}let n=d.findForm(e),r=d.findInput(e);d.ensureUniqueId(e,r),d.trackFilled(r);let o=lt(e),a=C(ge(e));if(o.autoSave||m.clear(a),!ct()){d.showError(e,t.noCrypto),d.attachSubmit(n,()=>d.showError(e,t.noCrypto));return}let s=it(o);if(!s.ok){d.showError(e,o.wpm),d.attachSubmit(n,()=>d.showError(e,o.wpm));return}let i=s.wire,l={id:a,version:i.version,salt:i.saltHex,kdfKey:i.kdfKey},u=!1,p=async(c,f,A)=>{if(u)return;u=!0,r&&(r.value=""),f==="manual"&&o.autoSave&&m.save(l,A);let k=await at.swapInDecryptedDOM(e,c);f==="cached"&&d.addForgetButton(k,t,()=>m.clear(a)),ut(f,k)};d.attachSubmit(n,async()=>{d.clearError(e);let c=r?r.value:"";if(!c){d.showError(e,o.wpm),d.refocus(r);return}d.setBusy(n,r,!0);let f;try{f=await be.tryDecryptWithPassword({wire:i,password:c})}finally{d.setBusy(n,r,!1)}if(!f.ok){d.showError(e,o.wpm),d.refocus(r);return}await p(f.plaintext,"manual",f.key)});async function h(){if(!o.autoSave)return!1;let c=await m.load(l);if(!c||u)return!1;let f=await be.tryDecryptWithKey({key:c,wire:i});return f.ok?(await p(f.plaintext,"cached"),!0):(u||m.clear(a),!1)}h().then(c=>{let f=document.activeElement;!c&&!u&&r&&(!f||f===document.body)&&r.focus()})}function H(e){e=e||document;let t=Array.prototype.slice.call(e.querySelectorAll(E));e.matches&&e.matches(E)&&t.unshift(e);for(let n=0;n<t.length;n++)dt(t[n])}if(!window.hexoBlogEncrypt){window.hexoBlogEncrypt={init:H,forget:ft},m.purgeLegacy();let e=()=>window.hexoBlogEncrypt.init();["pjax:complete","pjax:success","swup:contentReplaced","turbo:load"].forEach(t=>{document.addEventListener(t,e)})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>H()):H();})();
2
2
  //# sourceMappingURL=hbe.bundle.js.map