Skip to content

Commit

Permalink
bug fix & feature add
Browse files Browse the repository at this point in the history
1. add enter to decrypt the blog data.
2. fix the bug when blog content has special content.
  • Loading branch information
D0n9X1n committed Oct 8, 2016
1 parent 9e89a77 commit cf3447b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<h4 class="hexo-blog-encrypt-message">' + data.message + '</h4>' + data.content;
Expand All @@ -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 = '<h4 class="hexo-blog-encrypt-message">' + hexo.config.encrypt.blogs[i].message + '</h4>' + data.content;
Expand Down
23 changes: 21 additions & 2 deletions lib/mcommon.js
Original file line number Diff line number Diff line change
@@ -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 == '') {
Expand Down Expand Up @@ -30,3 +31,21 @@ function htmlDecode (str) {
s = s.replace(/<br>/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();
}
};
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "1.1.4"
"version": "1.1.5"
}

0 comments on commit cf3447b

Please sign in to comment.