🚧 Feat: add content encryption crude demo (#123)

This commit is contained in:
Cell
2022-05-22 13:13:27 +08:00
parent fcf13346af
commit 692973e9f5
3 changed files with 105 additions and 4 deletions
+24 -4
View File
@@ -129,10 +129,30 @@
{{- end -}}
{{- /* Content */ -}}
<div class="content" id="content">
{{- /* Expiration Reminder */ -}}
{{- partial "single/expiration-reminder.html" . -}}
{{- dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}
{{- $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 -}}
<div
class="content"
id="content"
{{ with $params.password }}data-password="{{ md5 $params.password }}"{{ end }}
{{ with $params.password }}data-content="{{ $content }}"{{ end }}
>
{{- if not $params.password -}}
{{- /* Expiration Reminder */ -}}
{{- partial "single/expiration-reminder.html" . -}}
{{- $content -}}
{{- else -}}
{{- partial "single/decrypt-form.html" $params -}}
{{- end -}}
</div>
{{- /* Footer */ -}}