Chore: unified content encryption function

This commit is contained in:
Cell
2024-08-26 11:22:45 +08:00
parent 91f3c7c3cf
commit e7dd4c838c
5 changed files with 22 additions and 29 deletions
+2 -10
View File
@@ -16,16 +16,8 @@
{{- /* Content */ -}}
{{- $content := dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
{{- if $params.password -}}
{{- $saltLen := strings.RuneCount (trim $params.password " ") -}}
{{- $saltLen = cond (eq (mod $saltLen 2) 0) (add $saltLen 1) $saltLen -}}
{{- $base64EncodeContent := $content | base64Encode -}}
{{- $content = printf "%v%v%v"
(substr $base64EncodeContent 0 $saltLen)
(substr (sha256 $params.password) $saltLen)
(substr $base64EncodeContent $saltLen)
-}}
{{- end -}}
{{- /* Content Encryption */ -}}
{{- $content = dict "Content" $content "Password" $params.password | partial "function/content-encryption.html" | safeHTML -}}
<div class="content" id="content"
{{- with $params.password }} data-password="{{ hash.XxHash . }}"{{ end }}
{{- with $params.password }} data-content="{{ $content }}"{{ end -}}
@@ -0,0 +1,14 @@
{{- $content := .Content -}}
{{- if .Password -}}
{{- $saltLen := strings.RuneCount (trim .Password " ") -}}
{{- $saltLen = cond (eq (mod $saltLen 2) 0) (add $saltLen 1) $saltLen -}}
{{- $base64EncodeContent := $content | base64Encode -}}
{{- $content = printf "%v%v%v"
(substr $base64EncodeContent 0 $saltLen)
(substr (sha256 .Password) $saltLen)
(substr $base64EncodeContent $saltLen)
-}}
{{- end -}}
{{- return $content -}}
+1 -1
View File
@@ -1,4 +1,4 @@
{{- .Scratch.Set "version" "v0.3.10-466bb7b7" -}}
{{- .Scratch.Set "version" "v0.3.10-91f3c7c3" -}}
{{- .Scratch.Set "this" dict -}}
{{- partial "init/detection-env.html" . -}}
+2 -10
View File
@@ -160,16 +160,8 @@
{{- /* Content */ -}}
{{- $content := dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
{{- if $params.password -}}
{{- $saltLen := strings.RuneCount (trim $params.password " ") -}}
{{- $saltLen = cond (eq (mod $saltLen 2) 0) (add $saltLen 1) $saltLen -}}
{{- $base64EncodeContent := $content | base64Encode -}}
{{- $content = printf "%v%v%v"
(substr $base64EncodeContent 0 $saltLen)
(substr (sha256 $params.password) $saltLen)
(substr $base64EncodeContent $saltLen)
-}}
{{- end -}}
{{- /* Content Encryption */ -}}
{{- $content = dict "Content" $content "Password" $params.password | partial "function/content-encryption.html" | safeHTML -}}
<div class="content" id="content"
{{- with $params.endFlag }} data-end-flag="{{ . }}"{{ end }}
{{- with $params.password }} data-password="{{ xxhash . }}"{{ end }}
+3 -8
View File
@@ -10,15 +10,10 @@
{{- end -}}
{{- if $password -}}
{{- /* Content */ -}}
{{- $content := .Inner | .Page.RenderString -}}
{{- $saltLen := strings.RuneCount (trim $password "") -}}
{{- $saltLen = cond (eq (mod $saltLen 2) 0) (add $saltLen 1) $saltLen -}}
{{- $base64EncodeContent := $content | base64Encode -}}
{{- $content = printf "%v%v%v"
(substr $base64EncodeContent 0 $saltLen)
(substr (sha256 $password) $saltLen)
(substr $base64EncodeContent $saltLen)
-}}
{{- /* Content Encryption */ -}}
{{- $content = dict "Content" $content "Password" $password | partial "function/content-encryption.html" | safeHTML -}}
<fixit-encryptor class="fixit-encryptor-shortcode">
<div class="fixit-decryptor-container">