diff --git a/TODO.md b/TODO.md
index 659beb5..189a681 100644
--- a/TODO.md
+++ b/TODO.md
@@ -6,3 +6,4 @@
##BUG
1. √ ~~hexo g will not work when the config file with no blogs block.~~
+2. if blog content has special character, it will crush.
diff --git a/index.js b/index.js
index ddb80a4..684974b 100644
--- a/index.js
+++ b/index.js
@@ -51,7 +51,10 @@ hexo.extend.filter.register("after_post_render", function (data) {
if (!('message' in data && data.message)) {
data.message = hexo.config.encrypt.default_message;
}
+
data.content = escape(data.content);
+ data.content = CryptoJS.enc.Utf8.parse(data.content);
+ data.content = CryptoJS.enc.Base64.stringify(data.content);
data.content = CryptoJS.AES.encrypt(data.content, data.password).toString();
data.content = data.template.replace('{{content}}', data.content);
data.content = '
' + data.message + '
' + data.content;
@@ -77,7 +80,10 @@ hexo.extend.filter.register("after_post_render", function (data) {
if (!hexo.config.encrypt.blogs[i].message) {
hexo.config.encrypt.blogs[i].message = hexo.config.encrypt.default_message;
}
+
data.content = escape(data.content);
+ data.content = CryptoJS.enc.Utf8.parse(data.content);
+ data.content = CryptoJS.enc.Base64.stringify(data.content);
data.content = CryptoJS.AES.encrypt(data.content, hexo.config.encrypt.blogs[i].password).toString();
data.content = hexo.config.encrypt.blogs[i].template.replace('{{content}}', data.content);
data.content = '' + hexo.config.encrypt.blogs[i].message + '
' + data.content;
diff --git a/lib/mcommon.js b/lib/mcommon.js
index 8bb2966..7130809 100644
--- a/lib/mcommon.js
+++ b/lib/mcommon.js
@@ -1,8 +1,9 @@
function decryptAES() {
var pass = document.getElementById("pass").value;
try {
- var bytes = CryptoJS.AES.decrypt(document.getElementById("encrypt-blog").innerHTML.trim(), pass);
- var content = bytes.toString(CryptoJS.enc.Utf8);
+ var content = CryptoJS.AES.decrypt(document.getElementById("encrypt-blog").innerHTML.trim(), pass);
+ content = content.toString(CryptoJS.enc.Utf8);
+ content = decodeBase64(content);
console.log(content);
content = unescape(content);
if (content == '') {
@@ -30,3 +31,21 @@ function htmlDecode (str) {
s = s.replace(/
/g, "\n");
return s;
}
+
+function decodeBase64(content) {
+ content = CryptoJS.enc.Base64.parse(content);
+ content = CryptoJS.enc.Utf8.stringify(content);
+ return content;
+}
+
+
+// add enter to decrypt
+window.onload = function() {
+ console.log('register');
+ document.getElementById("pass").onkeypress = function(keyPressEvent) {
+ console.log(keyPressEvent.keyCode === 13);
+ if (keyPressEvent.keyCode === 13) {
+ decryptAES();
+ }
+ };
+};
diff --git a/package.json b/package.json
index 47dbf0e..fda50e0 100644
--- a/package.json
+++ b/package.json
@@ -33,5 +33,5 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
- "version": "1.1.4"
+ "version": "1.1.5"
}