hexo-blog-encrypt 4.0.3 → 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,372 +1,79 @@
1
1
  # hexo-blog-encrypt
2
2
 
3
- [![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)
4
- [![npm](https://img.shields.io/npm/v/hexo-blog-encrypt?logo=npm&color=brightgreen)](https://www.npmjs.com/package/hexo-blog-encrypt)
5
- [![npm downloads](https://img.shields.io/npm/dm/hexo-blog-encrypt?logo=npm&label=downloads)](https://www.npmjs.com/package/hexo-blog-encrypt)
6
- [![License](https://img.shields.io/npm/l/hexo-blog-encrypt?color=brightgreen)](./LICENSE)
7
- [![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)
8
- [![Live Demo](https://img.shields.io/badge/demo-online-brightgreen?logo=github)](https://d0n9x1n.github.io/hexo-blog-encrypt/)
3
+ 在静态 Hexo 博客上发布文章,用密码分享正文。Hexo 在构建时加密,读者在浏览器中解锁。无需注册账号,也不需要解密服务器。
9
4
 
10
- #### 提 issue 之前,请务必提供复现方式,log,配置信息等必要信息。良好的 issue 可以节省双方的时间。
11
- *请严格按照模版要求,不明确的 issue 将直接关闭。*
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)
12
6
 
13
- **参考 issue:**
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/)
14
8
 
15
- > + [Issue 83](https://github.com/MikeCoder/hexo-blog-encrypt/issues/83)
16
- > + [Issue 68](https://github.com/MikeCoder/hexo-blog-encrypt/issues/68)
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/)
17
14
 
18
- ## 这是个啥
15
+ ## 给第一篇文章加密
19
16
 
20
- - ~~首先, 这是 Hexo 生态圈中 **最好的** 博客加密插件~~
21
-
22
- - 你可能需要写一些私密的博客, 通过密码验证的方式让人不能随意浏览.
23
-
24
- - 这在 wordpress, emlog 或是其他博客系统中都很容易实现, 然而 hexo 除外. :(
25
-
26
- - 为了解决这个问题, 让我们有请 "hexo-blog-encrypt".
27
-
28
- ## 特性
29
-
30
- - 一旦你输入了正确的密码, 加密的文章会在浏览器端解密. 默认情况下密码 **不会** 被持久化; 在文章信息头或 `_config.yml` 中设置 `autoSave: true` 之后, 派生出的密钥才会被缓存到 `localStorage`, 这样下次刷新同一页面时就能自动解密. 若文章中含有脚本, 它将会在解密后被正确执行.
31
-
32
- - 支持按标签加密.
33
-
34
- - 所有的核心功能都是由原生的 API 所提供的. 在 Node.js中, 我们使用 [Crypto](https://nodejs.org/dist/latest-v12.x/docs/api/crypto.html). 在浏览器中, 我们使用 [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API).
35
-
36
- - [PBKDF2](https://tools.ietf.org/html/rfc2898) 与 [SHA-256](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf) 被用于派生密钥, 我们使用 [AES-256-GCM](https://csrc.nist.gov/publications/detail/sp/800-38d/final) 进行带认证的加解密 — GCM 自带的 auth tag 即可检测密文被篡改 (取代了 v3 中独立的 HMAC 步骤).
37
-
38
- - 我们广泛地使用 Promise 来进行异步操作, 以此确保线程不被阻塞.
39
-
40
- - 加密页面多主题支持, 现在已经支持的主题有 [`default`, `xray`], 更多的主题正在开发中.
41
-
42
- - 过时的浏览器将不能正常显示, 因此, 请升级您的浏览器.
43
-
44
- ## 在线演示
45
-
46
- - 点击 [Demo Page](https://d0n9x1n.github.io/hexo-blog-encrypt/), **所有的密码都是 `hello`**.
47
-
48
- ## 浏览器支持
49
-
50
- 运行时使用 Web Crypto (`crypto.subtle`), 因此需要 **安全上下文**
51
- (HTTPS 或 `http://localhost`). 已验证:
52
-
53
- | 浏览器 | 最低版本 | 备注 |
54
- | --- | --- | --- |
55
- | Chromium / Edge | 92+ | CI 中通过 Playwright 自动测试 |
56
- | Firefox | 90+ | |
57
- | Safari (macOS / iOS) | 14+ | 发版前手动冒烟 |
58
-
59
- 如果站点是通过非 localhost 的纯 HTTP 提供, 解密会静默失败
60
- (`crypto.subtle` 为 `undefined`). 生产环境请始终使用 HTTPS.
61
-
62
- ## 为什么要从 v3 升级
63
-
64
- v4 不是表面的刷新, 而是真正修复了 v3 的安全短板与 UX 痛点. 主要原因:
65
-
66
- - **更强的密码学.** **AES-256-GCM** 自带的 auth tag 取代了 v3 的
67
- AES-CBC + 独立 HMAC. 单一原语、单一鉴权路径、硬件加速, 并且免疫一类
68
- CBC padding-oracle 与 HMAC 比较 bug.
69
- - **每篇独立 salt + nonce.** v3 所有文章共用同一个 salt — 同样的密码
70
- 到处派生出同样的密钥. v4 每篇独立派生密钥 — 攻击者无法把对一个密码
71
- 的 PBKDF2 计算结果, 复用到其它使用相同密码的文章上.
72
- - **更强的 KDF 默认值.** v3 默认仅 **1,024** 轮 PBKDF2-SHA256 — 远低于
73
- 现代推荐值, 在现代硬件上很容易被批量爆破均摊. v4 默认 **250,000**
74
- 轮 (≈ 240× 单次工作量), 推荐 ≥ 600,000 (OWASP 2023). 可通过
75
- `kdf.iterations` 按文章覆盖.
76
- - **隐私默认关闭.** v3 总是把解密后的密钥缓存到 `localStorage`, 共享
77
- 设备的下一个用户可以直接重看. v4 默认 `autoSave: false`, 你按需开启
78
- (按文章或全局).
79
- - **行内错误提示.** v3 用 `window.alert()` 弹窗提示密码错 — 移动端
80
- 尤其打断流程. v4 直接把错误显示在密码框旁边 (`role="alert"`).
81
- - **可选的"解密"按钮.** 让不知道按 Enter 的访客也能用. 文案可配置.
82
- - **更小.** 抛弃了打包的 CryptoJS 依赖, 改用浏览器原生 Web Crypto
83
- API. 浏览器端 bundle ≈ 6 KB (minified).
84
- - **有测试.** 服务端套件 100% 行 / 分支 / 函数覆盖 + Playwright e2e
85
- 覆盖全部 8 个主题. v3 几乎没有自动化测试; v4 每次推送都跑回归.
86
-
87
- 如果你在意有人能拉到你生成的 HTML 后做离线密码爆破, 或者在意共用
88
- 设备上缓存密钥被偷看 — 请升级.
89
-
90
- 每条变化更深入的"为什么", 见 wiki:
91
- [Migration v3 → v4](https://github.com/D0n9X1n/hexo-blog-encrypt/wiki/Migration-v3-to-v4).
92
-
93
- ## 从 v3 升级
94
-
95
- v4 修改了密文格式 (AES-GCM, 每篇文章独立 salt + 每次加密独立 nonce).
96
- v3 加密的产物在 v4 下无法解密, 反之亦然. 升级步骤:
97
-
98
- 1. 升级插件: `npm install --save hexo-blog-encrypt@^4`.
99
- 2. 重新生成: `hexo clean && hexo generate`.
100
- 3. 如果使用 CDN, 请清空缓存 (按设计, 每次构建文章 HTML 都会变化 —
101
- 每次加密都使用新的 nonce — 但运行时资源 `lib/hbe.<hash>.js`
102
- 是按内容 hash 命名的, 只有 bundle 改变时 URL 才会变).
103
- 4. 可选: 从 `_config.yml` 与 front-matter 中删除 `wrong_hash_message`
104
- (v4 起废弃, v5 中删除).
105
-
106
- 不会触碰任何源 `.md` 文件. 完整的 break 列表与新增的 `decryptButton` /
107
- `autoSave` / `kdf.iterations` 等配置请见 [CHANGELOG.md](./CHANGELOG.md).
108
-
109
- ## 安装
110
-
111
- - `npm install --save hexo-blog-encrypt`
112
-
113
- - 或 `yarn add hexo-blog-encrypt` (需要) [Yarn](https://yarnpkg.com/en/))
114
-
115
- ## 快速使用
116
-
117
- - 将 "password" 字段添加到您文章信息头就像这样.
118
-
119
- ```markdown
120
-
121
- ---
122
- title: Hello World
123
- date: 2016-03-30 21:18:02
124
- password: hello
125
- ---
17
+ 在 Hexo 站点目录下安装插件(需要 Node.js 18+、Hexo 5+):
126
18
 
19
+ ```sh
20
+ npm install --save hexo-blog-encrypt
127
21
  ```
128
22
 
129
- - 再使用 `hexo clean && hexo g && hexo s` 在本地预览加密的文章.
130
-
131
- ## 设置优先级
132
-
133
- 文章信息头 > 按标签加密
134
-
135
- ## 高级设置
136
-
137
- ### 文章信息头
138
-
139
- ```markdown
140
-
141
- ---
142
- title: Hello World
143
- tags:
144
- - 作为日记加密
145
- date: 2016-03-30 21:12:21
146
- password: mikemessi
147
- abstract: 有东西被加密了, 请输入密码查看.
148
- message: 您好, 这里需要密码.
149
- wrong_pass_message: 抱歉, 这个密码看着不太对, 请再试试.
150
- # v4 起已废弃 — AES-GCM 已经将 “密码错误” 与 “密文被篡改” 这两类失败统一处理,
151
- # 该字段现在等同于 `wrong_pass_message`. 请改设 `wrong_pass_message`.
152
- wrong_hash_message: 抱歉, 这个文章不能被校验, 不过您还是能看看解密后的内容.
153
- ---
154
-
155
- ```
156
-
157
- ### `_config.yml`
158
-
159
- #### 示例
23
+ 在**一篇文章**的文件头中设置密码。请为自己的文章选择足够长且不重复的口令,不要使用演示密码。
160
24
 
161
25
  ```yaml
162
-
163
- # Security
164
- encrypt: # hexo-blog-encrypt
165
- abstract: 有东西被加密了, 请输入密码查看.
166
- message: 您好, 这里需要密码.
167
- tags:
168
- - {name: tagName, password: 密码A}
169
- - {name: tagName, password: 密码B}
170
- wrong_pass_message: 抱歉, 这个密码看着不太对, 请再试试.
171
- # v4 起已废弃 (等同于 `wrong_pass_message`), 详见上方说明.
172
- wrong_hash_message: 抱歉, 这个文章不能被校验, 不过您还是能看看解密后的内容.
173
-
174
- # ── v4 新配置 (全部可选, 均有安全的默认值) ────────────────────────────
175
- # 在密码框旁渲染一个可见的 “解密” 按钮.
176
- # 主题模板若已经通过 `<%- decrypt_button %>` 自带按钮则会忽略本配置.
177
- # 默认: true.
178
- decryptButton:
179
- show: true
180
- text: 解密
181
-
182
- # 是否将派生出的 AES 密钥缓存到 localStorage, 让刷新页面跳过密码输入.
183
- # 默认 OFF — 可在文章 front-matter 中通过 `autoSave: true` 单独开启,
184
- # 也可以在这里全局开启. 缓存键命名空间为 `hbe.v4.<post-permalink-hash>`.
185
- autoSave: false
186
-
187
- # 让同一篇文章的 PBKDF2 salt 在 clean build 间保持稳定, 文章身份来自
188
- # 当前实现中的 post permalink. 默认: false. 配合 autoSave 时, 适用于
189
- # Cloudflare Pages、Vercel、Netlify、GitHub Actions 等每次部署都会从
190
- # 干净环境重新生成 HTML 的静态部署平台.
191
- #
192
- # 只稳定 salt; AES-GCM nonce 每次加密仍然随机, 避免 nonce reuse.
193
- # 如果文章 permalink 改变, stable salt 也会改变, 该页面已有的
194
- # localStorage 缓存会失效.
195
- stableSalt: false
196
-
197
- # PBKDF2 迭代次数. 下限: 100_000. 推荐 ≥ 600_000
198
- # (OWASP 2023 关于 PBKDF2-SHA256 的推荐). 低于推荐值时构建会打印 warning.
199
- # 默认: 250_000.
200
- kdf:
201
- iterations: 250000
202
-
203
- ```
204
-
205
- `autoSave` 读取缓存密钥时会比较缓存中的 salt 与当前页面 salt. 仅 nonce
206
- 变化不会提前删除缓存; 浏览器会使用缓存密钥配合当前页面的 nonce 与密文尝试
207
- 解密. 如果 AES-GCM 认证失败, 该缓存条目会被清除, 访客需要重新输入密码.
208
-
209
- #### 对博文禁用 Tag 加密
210
-
211
- 只需要将博文头部的 `password` 设置为 `""` 即可取消 Tag 加密.
212
-
213
- Example:
214
-
215
- ```
216
26
  ---
217
- title: Callback Test
218
- date: 2019-12-21 11:54:07
219
- tags:
220
- - A Tag should be encrypted
221
- password: ""
27
+ title: 旅行手记
28
+ theme: wave
29
+ password: { env: POST_PASSWORD }
30
+ abstract: 这次旅行的记录。想读正文,可以向我索取密码。
222
31
  ---
223
-
224
- Use a "" to diable tag encryption.
225
- ```
226
-
227
- ### 配置优先级
228
-
229
- 文章信息头 > `_config.yml` (站点根目录下的) > 默认配置
230
-
231
- ### 关于 Callback 函数
232
- 在部分博客中, 解密后部分元素可能无法正常显示或者表现, 这属于已知问题. 目前的解决办法是通过自行查阅自己的博客中的代码, 了解到在 onload 事件发生时调用了哪些函数, 并将这些函数挑选后写入到博客内容中. 如:
233
-
234
32
  ```
235
- ---
236
- title: Callback Test
237
- date: 2019-12-21 11:54:07
238
- tags:
239
- - Encrypted
240
- ---
241
33
 
242
- This is a blog to test Callback functions. You just need to add code at the last of your post like following:
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)。
243
35
 
244
- It will be called after the blog decrypted.
36
+ **哪些内容仍然公开?** 标题、摘要,以及你另外发布的 Markdown 源文件或原始媒体都不会因此保密。请勿把私密源文件提交到公开仓库。访客可以下载密文后离线猜测密码;若需要按账号限制访问,请使用具备访问控制的托管服务。[了解安全模型 →](https://github.com/D0n9X1n/hexo-blog-encrypt/wiki/Security-Model-zh-CN)
245
37
 
246
- <script>
247
- // 添加一个 script tag 与代码在文章末尾.
248
- alert("Hello World");
249
- </script>
250
- ```
38
+ ## 选择喜欢的样式
251
39
 
252
- 例子在: [Callback 例子](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/callback/).
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/) |
253
43
 
254
- ### 解密后的触发事件
44
+ 可以在单篇文章或全站配置里设置 `theme:`。11 种样式使用相同的加密方式;八个经典主题保留各自获得焦点和填入密码时的交互效果。
255
45
 
256
- 插件在解密后向 `window` 发送一次 `hexo-blog-decrypt` 事件。
257
- `event.detail.mode` 为 `manual`(输入密码)或 `cached`(使用缓存密钥)。
258
- 请监听事件,而不是手动触发:
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/)
259
47
 
260
- ```js
261
- window.addEventListener('hexo-blog-decrypt', function (event) {
262
- // 在这里重新初始化主题中的目录、代码高亮等功能。
263
- console.log('Decrypted:', event.detail.mode);
264
- });
265
- ```
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/)
266
49
 
267
- 从 **4.0.3** 起,普通外部脚本按文章中的顺序加载完成后,才执行后续内联脚本。
268
- 这解决了 DPlayer 等组件在其依赖库尚未加载时就初始化的问题。
269
- 外部脚本加载成功、失败或达到每个脚本 **15 秒** 的等待上限后,才发送解密事件;
270
- 原有 `onload` / `onerror` 处理函数保持不变。超时不等于取消,脚本可能稍后执行。
271
- 带有显式 `async` 的外部脚本仍独立加载;动态恢复的 `defer` 不会重新产生页面解析阶段。
272
- 内联 `type="module"` 脚本及脚本内部的异步任务保留浏览器原生时序,不保证在解密事件前完成。
273
- 依赖这些任务时,请使用它们自己的就绪信号。
50
+ ## 发布前须知
274
51
 
275
- [脚本加载顺序示例](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/script-order/)
276
- (密码 `hello`)同时展示普通解密与缓存密钥解密。
52
+ 插件 **v4.2.0** 写入格式 5,仍可读取格式 4 的旧文章。加密使用 scrypt 和 AES-256-GCM,不依赖其他 npm 运行时包。读者需要通过 HTTPS 或 localhost 访问。密钥缓存**默认关闭**,共享设备请保持关闭。
277
53
 
278
- ### 对 TOC 进行加密
54
+ <details>
55
+ <summary><strong>密码、密钥缓存与重新构建</strong></summary>
279
56
 
280
- **不要在生成页面时将加密文章的 `post.origin` 渲染到 HTML 中。**
281
- 它是供旧版 Hexo 集成使用的明文;即使用 `display:none` 隐藏目录,标题仍会泄露。
282
- 搜索和 feed 插件也必须排除加密文章的明文字段。
57
+ | 文章文件头 | 作用 |
58
+ | --- | --- |
59
+ | `password: { env: NAME }` | 从构建环境读取密码,也可用于 `encrypt.tags[].password`。变量缺失或为空时,构建会失败。 |
60
+ | `password: ""` | 即使标签匹配加密规则,这篇文章也保持公开。 |
283
61
 
284
- 在主题模板中,仅为未加密文章生成服务端目录。例如:
62
+ `autoSave` 将不可导出的 CryptoKey 保存在 IndexedDB 中,不保存密码:格式 5 使用 HKDF 基础密钥,格式 4 使用 AES-GCM 密钥。升级会清除旧版保存的原始密钥,读者可能需要重新输入一次密码。同源代码仍可使用缓存的密钥。读者可点击“忘记已保存的密钥”;`window.hexoBlogEncrypt.forget(target?)` 只有在存储事务完成后才确认删除成功。
285
63
 
286
- ```ejs
287
- <% if (post.toc === true && !post.encrypt) { %>
288
- <div class="toc-article"><%- toc(post.content, {list_number: true}) %></div>
289
- <% } %>
290
- <%- post.content %>
291
- ```
292
-
293
- 加密文章的目录应在 `hexo-blog-decrypt` 回调中,使用解密后的
294
- `#hexo-blog-encrypt` 内容和主题的客户端目录功能生成,而不是发布隐藏的明文目录。
295
-
296
- ### 禁用 Log
297
- If you want to disable the logging, you can add a silent property in `_config.yml` and set it to true.
298
- 如果你想要禁止使用 Log, 你可以在 `_config.yml` 中增加一个 silent 属性, 并将其设置为 true.
299
-
300
- ```yaml
301
- # Security
302
- encrypt: # hexo-blog-encrypt
303
- silent: true
304
- ```
305
-
306
- 这样就会禁止如 `INFO hexo-blog-encrypt: encrypting "{Blog Name}" based on Tag: "EncryptedTag".` 的日志.
307
-
308
- ### 加密主题
309
-
310
- 之前, 我们尝试使用 `template` 关键字来让用户能修改自己的主题. 后来发现真不是一个好主意. 所以我们现在引入了主题: `theme` 关键字.
311
-
312
- 你可以简单的使用 `theme` 在 `_config.yml` 里或者文章头, 如下:
313
-
314
- ### 文章信息头
315
-
316
- ```markdown
317
-
318
- ---
319
- title: Hello World
320
- tags:
321
- - 作为日记加密
322
- date: 2016-03-30 21:12:21
323
- password: mikemessi
324
- abstract: 有东西被加密了, 请输入密码查看.
325
- message: 您好, 这里需要密码.
326
- theme: xray
327
- wrong_pass_message: 抱歉, 这个密码看着不太对, 请再试试.
328
- # v4 起已废弃 (等同于 `wrong_pass_message`), 详见 “高级设置”.
329
- wrong_hash_message: 抱歉, 这个文章不能被校验, 不过您还是能看看解密后的内容.
330
- ---
331
-
332
- ```
333
-
334
- ### 在 `_config.yml`
335
-
336
- #### 示例
337
-
338
- ```yaml
339
-
340
- # Security
341
- encrypt: # hexo-blog-encrypt
342
- abstract: 有东西被加密了, 请输入密码查看.
343
- message: 您好, 这里需要密码.
344
- tags:
345
- - {name: tagName, password: 密码A}
346
- - {name: tagName, password: 密码B}
347
- theme: xray
348
- wrong_pass_message: 抱歉, 这个密码看着不太对, 请再试试.
349
- # v4 起已废弃 (等同于 `wrong_pass_message`), 详见 “高级设置”.
350
- wrong_hash_message: 抱歉, 这个文章不能被校验, 不过您还是能看看解密后的内容.
351
-
352
- ```
64
+ `stableSalt` 和 `autoSave` 默认关闭。在 Cloudflare Pages、Vercel、Netlify 或 GitHub Actions 上,`stableSalt: true` 可让缓存跨干净构建继续生效。permalink 改变后,旧缓存失效。每次加密仍使用随机 nonce。承诺值不匹配或 AES-GCM 认证失败时,浏览器会清除缓存。
353
65
 
354
- 你可以在线挑选你喜欢的主题,并应用到你的博客中:
66
+ </details>
355
67
 
356
- + [default](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/default/)
357
- + [blink](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/blink/)
358
- + [shrink](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/shrink/)
359
- + [flip](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/flip/)
360
- + [up](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/up/)
361
- + [surge](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/surge/)
362
- + [wave](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/wave/)
363
- + [xray](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/xray/)
68
+ <details>
69
+ <summary><strong>加密、资源完整性与主题集成</strong></summary>
364
70
 
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 可信。
365
72
 
366
- ## 许可
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/)。
367
74
 
368
- 看看 [LICENSE](./LICENSE).
75
+ </details>
369
76
 
370
- ## 感谢
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)
371
78
 
372
- Collaborator - [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)。
@@ -10,15 +10,16 @@
10
10
  {{hbeEncryptedData}}
11
11
  </script>
12
12
  <div class="hbe hbe-content">
13
- <form id="hbeForm" class="hbe hbe-form" onsubmit="return false">
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>
13
+ <form id="hbeForm" class="hbe hbe-form">
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 p=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var m=p((ot,x)=>{"use strict";function D(e,t){if(!e)return;e.setAttribute("aria-busy",t?"true":"false");let n=e.querySelector(".hbe-button");n&&(n.disabled=!!t);let r=e.querySelector("#hbePass");r&&(r.disabled=!!t)}function B(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=e.querySelector("#hbeForm");r?r.parentNode.insertBefore(n,r.nextSibling):e.appendChild(n)}n.textContent=t}function k(e){let t=e.querySelector('[role="alert"]');t&&(t.textContent="")}function M(e){let t=e.querySelector("#hbePass");return t?t.value:""}function P(e,t){e&&e.addEventListener("submit",n=>{n.preventDefault(),t()})}x.exports={setBusy:D,showError:B,clearError:k,readPassword:M,attachSubmit:P}});var b=p((at,w)=>{"use strict";var O=new TextDecoder("utf-8",{fatal:!0}),K=new TextEncoder;function u(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 g(e,t,n){let r=await crypto.subtle.importKey("raw",K.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 y(e,t,n){let r=await crypto.subtle.decrypt({name:"AES-GCM",iv:t,tagLength:128},e,n);return O.decode(r)}async function L({password:e,saltHex:t,nonceHex:n,ciphertextHex:r,iterations:o}){try{let a=u(t),c=u(n),i=u(r);if(i.length<16)return{ok:!1};let d=await g(e,a,o);return{ok:!0,plaintext:await y(d,c,i),key:d}}catch(a){return{ok:!1}}}async function R({key:e,nonceHex:t,ciphertextHex:n}){try{let r=u(t),o=u(n);return o.length<16?{ok:!1}:{ok:!0,plaintext:await y(e,r,o)}}catch(r){return{ok:!1}}}w.exports={tryDecryptWithPassword:L,tryDecryptWithKey:R,deriveKey:g,decryptWithKey:y,hexToBytes:u}});var T=p((ct,v)=>{"use strict";var q=/^(?:application|text)\/(?:x-)?(?:java|ecma)script$|^text\/(?:javascript1\.[0-5]|jscript|livescript)$/i;function S(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 E(e){let t=document.createElement("div");return t.innerHTML=e,t}function N(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===""||q.test(r)?"classic":"data"}function G(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 F(e){let t=[],n="noModule"in document.createElement("script");for(let r of e.querySelectorAll("script")){if(!e.contains(r))continue;let o=N(r);if(o==="data"||o==="classic"&&r.noModule&&n||o==="module"&&!n)continue;let a=S(r),c=o!=="declarative"&&a.hasAttribute("src"),i=c&&a.hasAttribute("async");o==="classic"&&c&&!i&&(a.async=!1);let d=G(r,a,c);i?t.push(d):await d}await Promise.all(t)}async function W(e,t){let n=E(t);return n.id="hexo-blog-encrypt",n.classList.add("hbe","hbe-decrypted-content"),e.parentNode.replaceChild(n,e),await F(n),n}v.exports={getExecutableScript:S,convertHTMLToElement:E,swapInDecryptedDOM:W}});var I=p((st,_)=>{"use strict";var A="hbe.v4.";function l(e){return A+e}function Y(e){let t="";for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}function U(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 V({pageKey:e,key:t,saltHex:n,nonceHex:r,autoSave:o}){if(o)try{let a=await crypto.subtle.exportKey("raw",t),c={version:4,dk:Y(new Uint8Array(a)),salt:n,nonce:r};localStorage.setItem(l(e),JSON.stringify(c))}catch(a){}}async function j({pageKey:e,expectedSaltHex:t}){let n;try{let r=localStorage.getItem(l(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(l(e))}catch(r){}return null}if(n.salt!==t){try{localStorage.removeItem(l(e))}catch(r){}return null}try{let r=U(n.dk);return await crypto.subtle.importKey("raw",r,{name:"AES-GCM"},!0,["decrypt"])}catch(r){try{localStorage.removeItem(l(e))}catch(o){}return null}}function J(e){try{localStorage.removeItem(l(e))}catch(t){}}_.exports={save:V,load:j,clear:J,STORAGE_KEY_PREFIX:A,SCHEMA_VERSION:4}});var s=m(),C=b(),X=T(),f=I(),$="4";function z(e){let t=e.dataset,n=e.querySelector("script#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)||25e4,autoSave:t.autoSave==="true",ciphertextHex:n?n.textContent.trim():""}}function Q(e){try{window.dispatchEvent(new CustomEvent("hexo-blog-decrypt",{detail:{mode:e}}))}catch(t){try{window.dispatchEvent(new Event("hexo-blog-decrypt"))}catch(n){}}}function h(){return location.pathname+location.search}async function Z(e,t,n){await X.swapInDecryptedDOM(e,t),Q(n)}async function tt(e,t,n){if(!t.autoSave)return!1;let r=await f.load({pageKey:h(),expectedSaltHex:t.saltHex});if(!r)return!1;let o=await C.tryDecryptWithKey({key:r,nonceHex:t.nonceHex,ciphertextHex:t.ciphertextHex});return o.ok?(await n(o.plaintext,"cached"),!0):(f.clear(h()),!1)}async function et(e,t,n,r){s.clearError(e),s.setBusy(n,!0);let o=s.readPassword(n);if(!o){s.setBusy(n,!1),s.showError(e,t.wpm);return}let a;try{a=await C.tryDecryptWithPassword({password:o,saltHex:t.saltHex,nonceHex:t.nonceHex,ciphertextHex:t.ciphertextHex,iterations:t.iterations})}finally{s.setBusy(n,!1)}if(!a.ok){s.showError(e,t.wpm);return}t.autoSave&&await f.save({pageKey:h(),key:a.key,saltHex:t.saltHex,nonceHex:t.nonceHex,autoSave:!0}),await r(a.plaintext,"manual")}async function H(){let e=document.getElementById("hexo-blog-encrypt");if(!e)return;let t=z(e);if(t.format!==$){s.showError(e,"hexo-blog-encrypt: this page was built with an incompatible plugin version. Rebuild the site after upgrading the plugin.");return}let n=!1,r=async(c,i)=>{n||(n=!0,await Z(e,c,i))},o=e.querySelector("#hbeForm");if(s.attachSubmit(o,()=>et(e,t,o,r)),!await tt(e,t,r)&&!n){let c=e.querySelector("#hbePass");c&&c.focus()}}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",H):H();})();
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