🚧 Fix: add Chinese and emoji decrypt support (#123)

This commit is contained in:
Cell
2022-05-25 14:34:34 +08:00
parent dc7f002260
commit db70d55217
9 changed files with 174 additions and 12 deletions
+1
View File
@@ -26,6 +26,7 @@ libFiles:
cookieconsentJS: cookieconsent@3.1.1/build/cookieconsent.min.js
# crypto-js@4.1.1 https://github.com/brix/crypto-js
cryptoCoreJS: crypto-js@4.1.1/core.js
cryptoEncBase64JS: crypto-js@4.1.1/enc-base64.js
cryptoMd5JS: crypto-js@4.1.1/md5.js
cryptoSha256JS: crypto-js@4.1.1/sha256.js
# echarts@5.2.2 https://github.com/apache/echarts
+1 -1
View File
@@ -32,7 +32,7 @@ FixItDecryptor = function (option = {}) {
if (inputMd5 !== password) {
return console.log('password error: ', input, inputMd5);
}
const base64DecodeContent = atob(base64EncodeContent.replace(inputSha256.slice(saltLen), ''));
const base64DecodeContent = CryptoJS.enc.Base64.parse(base64EncodeContent.replace(inputSha256.slice(saltLen), '')).toString(CryptoJS.enc.Utf8);
// TODO 记住解密状态
this.parentNode.classList.add('d-none');
$content.insertAdjacentHTML('afterbegin', base64DecodeContent);
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+136
View File
@@ -0,0 +1,136 @@
;(function (root, factory) {
if (typeof exports === "object") {
// CommonJS
module.exports = exports = factory(require("./core"));
}
else if (typeof define === "function" && define.amd) {
// AMD
define(["./core"], factory);
}
else {
// Global (browser)
factory(root.CryptoJS);
}
}(this, function (CryptoJS) {
(function () {
// Shortcuts
var C = CryptoJS;
var C_lib = C.lib;
var WordArray = C_lib.WordArray;
var C_enc = C.enc;
/**
* Base64 encoding strategy.
*/
var Base64 = C_enc.Base64 = {
/**
* Converts a word array to a Base64 string.
*
* @param {WordArray} wordArray The word array.
*
* @return {string} The Base64 string.
*
* @static
*
* @example
*
* var base64String = CryptoJS.enc.Base64.stringify(wordArray);
*/
stringify: function (wordArray) {
// Shortcuts
var words = wordArray.words;
var sigBytes = wordArray.sigBytes;
var map = this._map;
// Clamp excess bits
wordArray.clamp();
// Convert
var base64Chars = [];
for (var i = 0; i < sigBytes; i += 3) {
var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) {
base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
}
}
// Add padding
var paddingChar = map.charAt(64);
if (paddingChar) {
while (base64Chars.length % 4) {
base64Chars.push(paddingChar);
}
}
return base64Chars.join('');
},
/**
* Converts a Base64 string to a word array.
*
* @param {string} base64Str The Base64 string.
*
* @return {WordArray} The word array.
*
* @static
*
* @example
*
* var wordArray = CryptoJS.enc.Base64.parse(base64String);
*/
parse: function (base64Str) {
// Shortcuts
var base64StrLength = base64Str.length;
var map = this._map;
var reverseMap = this._reverseMap;
if (!reverseMap) {
reverseMap = this._reverseMap = [];
for (var j = 0; j < map.length; j++) {
reverseMap[map.charCodeAt(j)] = j;
}
}
// Ignore padding
var paddingChar = map.charAt(64);
if (paddingChar) {
var paddingIndex = base64Str.indexOf(paddingChar);
if (paddingIndex !== -1) {
base64StrLength = paddingIndex;
}
}
// Convert
return parseLoop(base64Str, base64StrLength, reverseMap);
},
_map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
};
function parseLoop(base64Str, base64StrLength, reverseMap) {
var words = [];
var nBytes = 0;
for (var i = 0; i < base64StrLength; i++) {
if (i % 4) {
var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
var bitsCombined = bits1 | bits2;
words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8);
nBytes++;
}
}
return WordArray.create(words, nBytes);
}
}());
return CryptoJS.enc.Base64;
}));
+3 -1
View File
@@ -1004,7 +1004,9 @@ enableEmoji = true
[params.pangu]
# For Chinese writing
# 适用于中文写作用户
enable = false
enable = true
# TODO 为空则全局生效
selector = ''
# Watermark config since v0.2.12
# Detail config see https://github.com/Lruihao/watermark#readme
+25 -5
View File
@@ -12,6 +12,8 @@ lightgallery: true
math:
enable: true
twemoji: true
tags:
- Test
- Encryption
@@ -27,18 +29,36 @@ menu:
I was shy, so I hid.
<!-- ## pangu test
與PM戰鬥的人,應當小心自己不要成為PM -->
<!-- emoji render error -->
<!-- more -->
![Hugo Theme FixIt](/images/Apple-Devices-Preview.png "Hugo Theme FixIt")
<!-- emoji render error -->
## Encrypted Content
### twemoji
<!-- ### emoji -->
coffee ☕
Gone camping! :tent: Be back soon.
That is so funny! :joy:
### pangu
```
與PM戰鬥的人,應當小心自己不要成為PM
```
與PM戰鬥的人,應當小心自己不要成為PM
### ruby
[Hugo]^(An open-source static site generator)
### math
$$ \ce{CO2 + C -> 2 CO} $$
$$ \ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-} $$
+2
View File
@@ -187,9 +187,11 @@
{{- /* Content Decryption */ -}}
{{- if $params.password -}}
{{- $cryptoCoreJS := $cdn.cryptoCoreJS | default "lib/crypto-js/core.js" -}}
{{- $cryptoEncBase64JS := $cdn.cryptoEncBase64JS | default "lib/crypto-js/enc-base64.js" -}}
{{- $cryptoMd5JS := $cdn.cryptoCoreJS | default "lib/crypto-js/md5.js" -}}
{{- $cryptoSha256JS := $cdn.cryptoCoreJS | default "lib/crypto-js/sha256.js" -}}
{{- dict "Source" $cryptoCoreJS "Minify" true "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
{{- dict "Source" $cryptoEncBase64JS "Minify" true "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
{{- dict "Source" $cryptoMd5JS "Minify" true "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
{{- dict "Source" $cryptoSha256JS "Minify" true "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
{{- dict "Source" "js/fixit-decryptor.js" "Minify" hugo.IsProduction "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
+4 -3
View File
@@ -895,13 +895,14 @@ class FixIt {
}
initPangu() {
// TODO 待优化
// TODO 待优化:只渲染
this.config.enablePangu && pangu.autoSpacingPage();
}
initFixItDecryptor() {
this.decryptor = new FixItDecryptor({
ondecrypted: () => {
this.initTwemoji();
this.initDetails();
this.initLightGallery();
this.initHighlight();
@@ -917,7 +918,7 @@ class FixIt {
});
this.initToc();
this.initTocListener();
// this.initPangu(); // TODO 中文转码有 BUG
this.initPangu();
}
});
this.decryptor.init();
@@ -1003,7 +1004,6 @@ class FixIt {
init() {
try {
this.initSVGIcon();
this.initTwemoji();
this.initMenu();
this.initSwitchTheme();
this.initSearch();
@@ -1014,6 +1014,7 @@ class FixIt {
if (this.#encrypted) {
this.initFixItDecryptor();
} else {
this.initTwemoji();
this.initDetails();
this.initLightGallery();
this.initHighlight();