import{$ as e,B as t,P as n,_ as r,f as i,g as a,h as o,l as s}from"./runtime-core.esm-bundler-CZvn3YaB.js";import{t as c}from"./plugin-vue_export-helper-CxTVcLa7.js";var l=JSON.parse(`{"path":"/guide/features/encryption/","title":"加密 | 指南","lang":"zh-CN","frontmatter":{"title":"加密","icon":"mdi:encryption-outline","createTime":"2024/03/04 15:58:48","permalink":"/guide/features/encryption/","description":"加密 在本主题中,支持 全站加密 、 部分页面加密 和 部分内容加密 等多种灵活的加密方式。 提示 由于 vuepress 是静态站点,其自身限制的原因,加密 仅仅只是 看起来 看不到内容, 并且在 编译时,不再将 内容 预渲染到 html 中,但实际上 还是能够从 站点源文件 中获取到内容。 因此,不建议将 加密 功能 认为是 安全可靠的。 请尽量避...","head":[["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"加密\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2026-02-12T15:55:21.000Z\\",\\"author\\":[]}"],["meta",{"property":"og:url","content":"https://theme-plume.vuejs.press/guide/features/encryption/"}],["meta",{"property":"og:site_name","content":"Plume 主题"}],["meta",{"property":"og:title","content":"加密"}],["meta",{"property":"og:description","content":"加密 在本主题中,支持 全站加密 、 部分页面加密 和 部分内容加密 等多种灵活的加密方式。 提示 由于 vuepress 是静态站点,其自身限制的原因,加密 仅仅只是 看起来 看不到内容, 并且在 编译时,不再将 内容 预渲染到 html 中,但实际上 还是能够从 站点源文件 中获取到内容。 因此,不建议将 加密 功能 认为是 安全可靠的。 请尽量避..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"zh-CN"}],["meta",{"property":"og:locale:alternate","content":"en-US"}],["meta",{"property":"og:updated_time","content":"2026-02-12T15:55:21.000Z"}],["meta",{"property":"article:modified_time","content":"2026-02-12T15:55:21.000Z"}],["link",{"rel":"alternate","hreflang":"en-us","href":"https://theme-plume.vuejs.press/en/guide/features/encryption/"}]]},"readingTime":{"minutes":4.9,"words":1469},"git":{"createdTime":1709915848000,"updatedTime":1770911721000,"contributors":[{"name":"pengzhanbo","username":"pengzhanbo","email":"volodymyr@foxmail.com","commits":11,"avatar":"https://avatars.githubusercontent.com/pengzhanbo?v=4","url":"https://github.com/pengzhanbo"}],"changelog":[{"hash":"b1f996cb0ec9ebd9135adf855de4363696f0161e","time":1770911721000,"email":"volodymyr@foxmail.com","author":"pengzhanbo","message":"feat(plugin-md-power): add ::: encrypt container, close #815 (#831)"},{"hash":"4d2361a7046214fe0f4e4af01831107fd00e38ad","time":1759849989000,"email":"volodymyr@foxmail.com","author":"pengzhanbo","message":"feat(theme)!: add collections support (#704)"},{"hash":"086528606e95cca2264b4c8685228e490e807807","time":1757479441000,"email":"volodymyr@foxmail.com","author":"pengzhanbo","message":"feat(theme): add password support for post frontmatter (#689)"},{"hash":"0fd6cac57412002f4d72dc10378789b529adc357","time":1742063370000,"email":"volodymyr@foxmail.com","author":"pengzhanbo","message":"refactor(theme): improve types and flat config (#524)"},{"hash":"0c53be8f10bec3e943a493111b321be89a5952cf","time":1731083728000,"email":"volodymyr@foxmail.com","author":"pengzhanbo","message":"docs: improve docs (#332)"},{"hash":"f69490af58d0d32d77ca109e062c702c1dfa891a","time":1723481804000,"email":"volodymyr@foxmail.com","author":"pengzhanbo","message":"docs: update docs"},{"hash":"822d861daef23a289c5e7720cdd7b0beb79b60c1","time":1711040997000,"email":"volodymyr@foxmail.com","author":"pengzhanbo","message":"docs: lint fix md"},{"hash":"2fb3da074776629502acf70e60da06022aa06b61","time":1710691945000,"email":"volodymyr@foxmail.com","author":"pengzhanbo","message":"docs: update theme docs"},{"hash":"920d3d115723141dfa8a35ec376c8e372f188a53","time":1710362649000,"email":"volodymyr@foxmail.com","author":"pengzhanbo","message":"docs: update docs"},{"hash":"ca097146cf4473f9ebfb04fe9e61708dcfd6d464","time":1709917771000,"email":"volodymyr@foxmail.com","author":"pengzhanbo","message":"docs: lint fix"}]},"autoDesc":true,"filePathRelative":"guide/features/encryption.md","headers":[],"bulletin":false}`),u={name:`encryption.md`},d={class:`code-block-title`,"data-title":`.vuepress/config.ts`},f={class:`code-block-title-bar`},p={class:`title`},m={class:`code-block-title`,"data-title":`.vuepress/config.ts`},h={class:`code-block-title-bar`},g={class:`title`},_={class:`code-block-title`,"data-title":`.vuepress/config.ts`},v={class:`code-block-title-bar`},y={class:`title`},b={class:`code-block-title`,"data-title":`.vuepress/config.ts`},x={class:`code-block-title-bar`},S={class:`title`},C={class:`code-block-title`,"data-title":`.vuepress/config.ts`},w={class:`code-block-title-bar`},T={class:`title`},E={class:`code-block-title`,"data-title":`.vuepress/config.ts`},D={class:`code-block-title-bar`},O={class:`title`};function k(c,l,u,k,A,j){let M=t(`VPIcon`),N=t(`VPLink`),P=t(`VPEncryptSnippet`);return n(),i(`div`,null,[l[17]||=o(`

加密

在本主题中,支持 全站加密部分页面加密部分内容加密 等多种灵活的加密方式。

提示

由于 vuepress 是静态站点,其自身限制的原因,加密 仅仅只是 看起来 看不到内容, 并且在 编译时,不再将 内容 预渲染到 html 中,但实际上 还是能够从 站点源文件 中获取到内容。 因此,不建议将 加密 功能 认为是 安全可靠的。

请尽量避免将 加密功能 应用于需要 严格保密 的内容 中。

已解锁的文章,仅在当前会话中可见。

启用加密功能

在 主题配置中,添加 encrypt 选项。

`,6),s(`div`,d,[s(`div`,f,[s(`span`,p,[r(M,{provider:`iconify`,name:`vscode-icons:file-type-typescript`}),l[0]||=a(`.vuepress/config.ts`,-1)])]),l[1]||=o(`
import { defineUserConfig } from 'vuepress'
import { plumeTheme } from 'vuepress-theme-plume'

export default defineUserConfig({
  theme: plumeTheme({
    encrypt: {
      // more options...
    }
  })
})
`,1)]),l[18]||=s(`h2`,{id:`全站加密`,tabindex:`-1`},[s(`a`,{class:`header-anchor`,href:`#全站加密`},[s(`span`,null,`全站加密`)])],-1),l[19]||=s(`p`,null,[a(`有些情况下,你可能 需要对 全站进行加密。 因此,你可以通过 `),s(`code`,null,`encrypt.global`),a(` 选项配置全站加密。 然后,通过配置 `),s(`code`,null,`encrypt.admin`),a(` 选项,设置一个或多个密码。`)],-1),s(`div`,m,[s(`div`,h,[s(`span`,g,[r(M,{provider:`iconify`,name:`vscode-icons:file-type-typescript`}),l[2]||=a(`.vuepress/config.ts`,-1)])]),l[3]||=o(`
export default defineUserConfig({
  theme: plumeTheme({
    encrypt: {
      global: true,
      admin: ['123456'],
    }
  })
})
`,1)]),l[20]||=s(`h2`,{id:`部分页面加密`,tabindex:`-1`},[s(`a`,{class:`header-anchor`,href:`#部分页面加密`},[s(`span`,null,`部分页面加密`)])],-1),l[21]||=s(`p`,null,[a(`大多数情况下,你可能只需需要 加密 某一篇文章、某一个目录 等。 因此,你可以通过 `),s(`code`,null,`encrypt.rules`),a(` 选项配置部分加密。`)],-1),s(`div`,_,[s(`div`,v,[s(`span`,y,[r(M,{provider:`iconify`,name:`vscode-icons:file-type-typescript`}),l[4]||=a(`.vuepress/config.ts`,-1)])]),l[5]||=o(`
export default defineUserConfig({
  theme: plumeTheme({
    encrypt: {
      rules: {
        // 可以是 md 文件的相对路径,对该文件加密
        '前端/基础.md': '123456',
        // 可以是 文件夹的路径,对该目录下所有文章加密
        '/notes/vuepress-theme-plume/': '123456',
        // 可以是 访问地址的请求路径,对该访问路径下所有文章加密
        '/vuepress-theme-plume/': '123456',
        // 可以是 具体的某个页面的请求路径,对该页面加密
        '/article/f8dnci3/': '123456',
        // 如果是 \`^\` 开头,则匹配该正则表达式的页面也会加密
        '^/(a|b)/': '123456',
      }
    }
  })
})
`,1)]),l[22]||=o(`

encrypt.rules 将作为 匹配规则, 将作为 该规则对应的密码,可以设置 一个或多个密码。

说明

Frontmatter

在 Markdown 文件的 Frontmatter 中,可以使用 password 设置文章的密码。

---
title: 加密的文章
password: 123456
---

还可以添加 passwordHint 选项,用于设置密码提示信息。

---
title: 加密的文章
password: 123456
passwordHint: 密码是 123456
---

示例

`,8),s(`p`,null,[l[7]||=a(`点击访问 `,-1),r(N,{href:`/article/enx7c9s/`},{default:e(()=>[...l[6]||=[a(`加密文章,密码:123456`,-1)]]),_:1})]),l[23]||=s(`h2`,{id:`部分内容加密`,tabindex:`-1`},[s(`a`,{class:`header-anchor`,href:`#部分内容加密`},[s(`span`,null,`部分内容加密`)])],-1),l[24]||=s(`h3`,{id:`配置`,tabindex:`-1`},[s(`a`,{class:`header-anchor`,href:`#配置`},[s(`span`,null,`配置`)])],-1),l[25]||=s(`p`,null,[a(`部分内容加密通过 `),s(`code`,null,`::: encrypt`),a(` 容器实现,需要配置 `),s(`code`,null,`markdown.encrypt`),a(` 选项:`)],-1),s(`div`,b,[s(`div`,x,[s(`span`,S,[r(M,{provider:`iconify`,name:`vscode-icons:file-type-typescript`}),l[8]||=a(`.vuepress/config.ts`,-1)])]),l[9]||=o(`
export default defineUserConfig({
  theme: plumeTheme({
    markdown: {
      encrypt: true, 
    }
  })
})
`,1)]),l[26]||=s(`p`,null,[a(`还可以给 `),s(`code`,null,`::: encrypt`),a(` 容器设置统一的默认密码:`)],-1),s(`div`,C,[s(`div`,w,[s(`span`,T,[r(M,{provider:`iconify`,name:`vscode-icons:file-type-typescript`}),l[10]||=a(`.vuepress/config.ts`,-1)])]),l[11]||=o(`
export default defineUserConfig({
  theme: plumeTheme({
    markdown: {
      encrypt: {
        password: 123456, 
      }
    }
  })
})
`,1)]),l[27]||=o(`

使用

使用 ::: encrypt 容器,将需要加密的内容包裹起来。 可以在容器中添加 password / pwd 属性,设置该容器的密码。 如果没有设置密码,将使用默认密码。

还可以在容器上添加 hint 属性,设置密码提示信息。

::: encrypt password="123456" hint="密码是连续的 6 位数"
这是加密的内容
:::

密码仅有一个生效,不支持同时设置多个密码。

示例

输入:

::: encrypt password="123456"
这是加密的内容
:::

输出:

`,9),r(P,{data:`eJwNjTsOwlAMBO/ieou39vvYuQpKEaog0QXRIO6ebXdm7J+dx3XaZvFc3nOlwa7j/bHtwbnAFvDWQR+Y8JggA0zH7NDGGChhOrLJXsjaYa+v+lIgpAuSGMqGlCxNQ61QEKyFKjgT8vTMuf9vzbYgNg==`,hint:``,"path-locale":`/`}),l[28]||=o(`

输入:

::: encrypt password="654321" hint="密码是连续的 6 位数"
这是加密的内容2
:::

输出:

`,3),r(P,{data:`eJwdjDEKAzEMBP+ieousbNnWfSVc4SJwgXQX0oT8PesDLWilYb52zPOwzVrLOpkPg53z9bbtzg4WhQkvN6Sjp1qsjWVFtQqIgGuuEJ477PmRwBcQVem6gqPCSaQ4+TgaYiDkaBhFOr2H4P33B+31IIQ=`,hint:`密码是连续的 6 位数`,"path-locale":`/`}),l[29]||=o(`

使用限制

对于被加密的内容,可以使用:

网络环境要求: 部分内容加密采用 Crypto API 实现, 因此,在 非 HTTPS 环境 下,将无法正常工作。

如果你是技术开发者,你可能需要知道的内容

原始 markdown 内容首先进过 markdown 渲染为 HTML 内容后,再进行加密;传输到客户端,再进行解密渲染。 解密后的内容会被包装为一个动态的 vue 组件,html 作为 template 传给该动态组件,因此,涉及到运行时编译 template 的内容。这导致了如果启用部分内容加密功能,那么就需要将 vue 切换到 esm-bundler 版本,以支持运行时编译, 这会比默认的 runtime-only 版本性能差一些,体积也会增加。

相关配置

`,3),s(`p`,null,[l[13]||=a(`以下配置支持在 `,-1),r(N,{href:`../../config/locales.md`},{default:e(()=>[...l[12]||=[a(`多语言配置`,-1)]]),_:1}),l[14]||=a(` 中使用。`,-1)]),l[30]||=o(`

encryptGlobalText

encryptPageText

encryptButtonText

encryptPlaceholder

示例

`,9),s(`div`,E,[s(`div`,D,[s(`span`,O,[r(M,{provider:`iconify`,name:`vscode-icons:file-type-typescript`}),l[15]||=a(`.vuepress/config.ts`,-1)])]),l[16]||=o(`
import { defineUserConfig } from 'vuepress'
import { plumeTheme } from 'vuepress-theme-plume'

export default defineUserConfig({
  theme: plumeTheme({
    locales: {
      '/': {
        encryptButtonText: 'Confirm',
        encryptPlaceholder: 'Enter password',
        encryptGlobalText: 'Only password can access this site',
        encryptPageText: 'Only password can access this page',
      }
    }
  })
})
`,1)])])}var A=c(u,[[`render`,k]]);export{l as _pageData,A as default};