diff --git a/index.js b/index.js
index 8ec7e60..c789e9f 100644
--- a/index.js
+++ b/index.js
@@ -18,6 +18,10 @@ const defaultConfig = {
const keySalt = textToArray('hexo-blog-encrypt的作者们都是大帅比!');
const ivSalt = textToArray('hexo-blog-encrypt是地表最强Hexo加密插件!');
+// As we can't detect the wrong password with AES-CBC,
+// so adding an empty tag and check it when decrption.
+const knownPrefix = "";
+
// disable log
var silent = false;
@@ -71,7 +75,7 @@ hexo.extend.filter.register('after_post_render', (data) => {
dlog('info', `hexo-blog-encrypt: encrypting "${data.title.trim()}" based on Tag: "${tagUsed}".`);
}
- data.content = data.content.trim();
+ data.content = knownPrefix + data.content.trim();
data.encrypt = true;
const key = crypto.pbkdf2Sync(password, keySalt, 1024, 32, 'sha256');
diff --git a/lib/blog-encrypt.js b/lib/blog-encrypt.js
index cd57143..8cc6552 100644
--- a/lib/blog-encrypt.js
+++ b/lib/blog-encrypt.js
@@ -8,6 +8,10 @@
const keySalt = textToArray('hexo-blog-encrypt的作者们都是大帅比!');
const ivSalt = textToArray('hexo-blog-encrypt是地表最强Hexo加密插件!');
+// As we can't detect the wrong password with AES-CBC,
+// so adding an empty div and check it when decrption.
+const knownPrefix = "";
+
const mainElement = document.getElementById('hexo-blog-encrypt');
const wrongPassMessage = mainElement.dataset['wpm'];
const wrongHashMessage = mainElement.dataset['whm'];
@@ -171,6 +175,11 @@
const decoder = new TextDecoder();
const decoded = decoder.decode(result);
+ // check the prefix, if not then we can sure here is wrong password.
+ if (!decoded.startsWith(knownPrefix)) {
+ throw "Decode successfully but not start with KnownPrefix.";
+ }
+
const hideButton = document.createElement('button');
hideButton.textContent = 'Encrypt again';
hideButton.type = 'button';
diff --git a/package.json b/package.json
index 41c9d6a..79f6f77 100644
--- a/package.json
+++ b/package.json
@@ -34,7 +34,7 @@
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint --ext .js ./"
},
- "version": "3.0.14",
+ "version": "3.0.15",
"devDependencies": {
"eslint": "^6.2.2"
}