Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f1a0b75e3 | ||
|
|
0de98e660b | ||
|
|
b017e7bda1 |
@@ -1,6 +1,6 @@
|
|||||||
NODE_ENV = developement
|
NODE_ENV = developement
|
||||||
VUE_APP_BASE_NAME = developement
|
VUE_APP_BASE_NAME = developement
|
||||||
VUE_APP_BASE_URL = http://localhost:8080
|
VUE_APP_BASE_URL = http://localhost:8080
|
||||||
VUE_APP_NOTE_MAX_COUNT = 409600
|
VUE_APP_NOTE_MAX_COUNT = 131072
|
||||||
VUE_APP_NOTE_MAX_DESC = 400K
|
VUE_APP_NOTE_MAX_DESC = 128K
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
NODE_ENV = production
|
NODE_ENV = production
|
||||||
VUE_APP_BASE_NAME = production
|
VUE_APP_BASE_NAME = production
|
||||||
VUE_APP_BASE_URL = https://flagnote.com
|
VUE_APP_BASE_URL = https://flagnote.com
|
||||||
VUE_APP_NOTE_MAX_COUNT = 409600
|
VUE_APP_NOTE_MAX_COUNT = 131072
|
||||||
VUE_APP_NOTE_MAX_DESC = 400K
|
VUE_APP_NOTE_MAX_DESC = 128K
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { getStoreKey } from "@/api/lock";
|
import { getStoreKey } from "@/api/lock";
|
||||||
import storage from "@/libs/storage";
|
import storage from "@/libs/storage";
|
||||||
import { md5, wrap} from "@/libs/secret";
|
import { md5, wrap, convertHexStringToUint8Array} from "@/libs/secret";
|
||||||
import NoteConstant from "@/libs/constants";
|
import NoteConstant from "@/libs/constants";
|
||||||
|
|
||||||
axios.interceptors.response.use(undefined, (err) => {
|
axios.interceptors.response.use(undefined, (err) => {
|
||||||
@@ -48,8 +48,13 @@ export function saveNote(noteForm, secret) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let bufferArrary = eval("[" + note.text + "]");
|
// let bufferArrary = eval("[" + note.text + "]");
|
||||||
let array = Uint8Array.from(bufferArrary);
|
// let array = Uint8Array.from(bufferArrary);
|
||||||
|
|
||||||
|
// let encoder = new TextEncoder()
|
||||||
|
// let array = encoder.encode(note.text)
|
||||||
|
let array = convertHexStringToUint8Array(note.text)
|
||||||
|
|
||||||
let blob = new Blob([array], { type: "application/octet-stream" });
|
let blob = new Blob([array], { type: "application/octet-stream" });
|
||||||
let form = new FormData();
|
let form = new FormData();
|
||||||
form.append("file", blob, noteForm.key);
|
form.append("file", blob, noteForm.key);
|
||||||
|
|||||||
@@ -4,6 +4,43 @@ import pako from "pako";
|
|||||||
|
|
||||||
const wasmFlate = window.wasm_bindgen;
|
const wasmFlate = window.wasm_bindgen;
|
||||||
|
|
||||||
|
|
||||||
|
CryptoJS.enc.Uint8Array = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WordArray转Uint8Array
|
||||||
|
* @param wordArray
|
||||||
|
* @returns {Uint8Array}
|
||||||
|
*/
|
||||||
|
stringify: function (wordArray) {
|
||||||
|
var len = wordArray.words.length,
|
||||||
|
u8_array = new Uint8Array(len << 2),
|
||||||
|
offset = 0, word, i;
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
word = wordArray.words[i];
|
||||||
|
u8_array[offset++] = word >> 24;
|
||||||
|
u8_array[offset++] = (word >> 16) & 0xff;
|
||||||
|
u8_array[offset++] = (word >> 8) & 0xff;
|
||||||
|
u8_array[offset++] = word & 0xff;
|
||||||
|
}
|
||||||
|
return u8_array;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uint8Array转WordArray
|
||||||
|
* @param u8arr
|
||||||
|
* @returns {WordArray}
|
||||||
|
*/
|
||||||
|
parse: function (u8arr) {
|
||||||
|
var len = u8arr.length;
|
||||||
|
var words = [];
|
||||||
|
for (var i = 0; i < len; i++) {
|
||||||
|
words[i >>> 2] |= (u8arr[i] & 0xff) << (24 - (i % 4) * 8);
|
||||||
|
}
|
||||||
|
return CryptoJS.lib.WordArray.create(words, len);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @word 要加密的内容
|
* @word 要加密的内容
|
||||||
* @keyWord String 服务器随机返回的关键字
|
* @keyWord String 服务器随机返回的关键字
|
||||||
@@ -11,14 +48,14 @@ const wasmFlate = window.wasm_bindgen;
|
|||||||
|
|
||||||
export function wrap(text, secretKey) {
|
export function wrap(text, secretKey) {
|
||||||
text = "FLAGNOTE#" + text;
|
text = "FLAGNOTE#" + text;
|
||||||
let result = aesEncrypt(text, secretKey);
|
let ui8ary = noteZip(text);
|
||||||
result = noteZip(result);
|
let result = aesEncrypt(convertUint8ArrayToWordArray(ui8ary), secretKey);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unwrap(storeText, secretKey) {
|
export function unwrap(text, secretKey) {
|
||||||
let result = noteUnzip(storeText);
|
let wdary = aesDecrypt(text, secretKey);
|
||||||
result = aesDecrypt(result, secretKey);
|
let result = noteUnzip(convertWordArrayToUint8Array(wdary));
|
||||||
if (result.startsWith("FLAGNOTE#")) {
|
if (result.startsWith("FLAGNOTE#")) {
|
||||||
return result.substring(9);
|
return result.substring(9);
|
||||||
}
|
}
|
||||||
@@ -37,39 +74,37 @@ export function aesEncrypt(word, keyWord) {
|
|||||||
let key = CryptoJS.enc.Utf8.parse(keyWord);
|
let key = CryptoJS.enc.Utf8.parse(keyWord);
|
||||||
let encrypted = CryptoJS.AES.encrypt(word, key, {
|
let encrypted = CryptoJS.AES.encrypt(word, key, {
|
||||||
mode: CryptoJS.mode.ECB,
|
mode: CryptoJS.mode.ECB,
|
||||||
padding: CryptoJS.pad.Pkcs7,
|
padding: CryptoJS.pad.ZeroPadding,
|
||||||
});
|
});
|
||||||
return encrypted.toString();
|
return encrypted.ciphertext.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
//解密
|
//解密
|
||||||
export function aesDecrypt(word, keyWord) {
|
export function aesDecrypt(word, keyWord) {
|
||||||
|
|
||||||
let key = CryptoJS.enc.Utf8.parse(keyWord);
|
let key = CryptoJS.enc.Utf8.parse(keyWord);
|
||||||
let decrypt = CryptoJS.AES.decrypt(word, key, {
|
var srcs = CryptoJS.enc.Hex.parse(word);
|
||||||
|
let decrypt = CryptoJS.AES.decrypt({
|
||||||
|
ciphertext: srcs
|
||||||
|
}, key, {
|
||||||
mode: CryptoJS.mode.ECB,
|
mode: CryptoJS.mode.ECB,
|
||||||
padding: CryptoJS.pad.Pkcs7,
|
padding: CryptoJS.pad.ZeroPadding,
|
||||||
});
|
});
|
||||||
return CryptoJS.enc.Utf8.stringify(decrypt).toString();
|
return decrypt;
|
||||||
}
|
}
|
||||||
|
|
||||||
//base64 encode
|
//base64 encode
|
||||||
export function encode(text) {
|
// export function encode(text) {
|
||||||
return Buffer.from(text, 'utf-8').toString('base64');
|
// return Buffer.from(text, 'utf-8').toString('base64');
|
||||||
}
|
// }
|
||||||
|
|
||||||
//base64 decode
|
//base64 decode
|
||||||
export function decode(text) {
|
// export function decode(text) {
|
||||||
return Buffer.from(text,'base64').toString('utf-8');
|
// return Buffer.from(text,'base64').toString('utf-8');
|
||||||
}
|
// }
|
||||||
|
|
||||||
export function noteUnzip(text) {
|
export function noteUnzip(wdary) {
|
||||||
let charData = text.split(",").map(function (x) {
|
let data = unzip(wdary);
|
||||||
return parseInt(x);
|
let text = new TextDecoder().decode(data);
|
||||||
});
|
|
||||||
let binData = new Uint8Array(charData);
|
|
||||||
let data = unzip(binData);
|
|
||||||
text = String.fromCharCode.apply(null, new Uint8Array(data));
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +131,13 @@ export function unzip(data){
|
|||||||
return pako.ungzip(data);
|
return pako.ungzip(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// function convertWordArrayToUint8Array(wordArray) {
|
function convertWordArrayToUint8Array(wordArray) {
|
||||||
|
|
||||||
|
let rr = CryptoJS.enc.Uint8Array.stringify(wordArray);
|
||||||
|
return rr;
|
||||||
|
// console.log(rr)
|
||||||
|
|
||||||
|
|
||||||
// var len = wordArray.words.length,
|
// var len = wordArray.words.length,
|
||||||
// u8_array = new Uint8Array(len << 2),
|
// u8_array = new Uint8Array(len << 2),
|
||||||
// offset = 0, word, i
|
// offset = 0, word, i
|
||||||
@@ -109,9 +150,14 @@ export function unzip(data){
|
|||||||
// u8_array[offset++] = word & 0xff;
|
// u8_array[offset++] = word & 0xff;
|
||||||
// }
|
// }
|
||||||
// return u8_array;
|
// return u8_array;
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
function convertUint8ArrayToWordArray(u8Array) {
|
||||||
|
|
||||||
|
let rr = CryptoJS.enc.Uint8Array.parse(u8Array);
|
||||||
|
return rr;
|
||||||
|
// console.log(rr)
|
||||||
|
|
||||||
// function convertUint8ArrayToWordArray(u8Array) {
|
|
||||||
// var words = [], i = 0, len = u8Array.length;
|
// var words = [], i = 0, len = u8Array.length;
|
||||||
|
|
||||||
// while (i < len) {
|
// while (i < len) {
|
||||||
@@ -127,4 +173,19 @@ export function unzip(data){
|
|||||||
// sigBytes: words.length * 4,
|
// sigBytes: words.length * 4,
|
||||||
// words: words
|
// words: words
|
||||||
// };
|
// };
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
export function convertHexStringToUint8Array(hexString) {
|
||||||
|
var result = [];
|
||||||
|
for (var i = 0; i < hexString.length; i += 2) {
|
||||||
|
result.push(parseInt(hexString.substr(i, 2), 16));
|
||||||
|
}
|
||||||
|
return Uint8Array.from(result);
|
||||||
|
// Uint8Array.from(hexString.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function convertUint8ArrayToHexString(byteArray) {
|
||||||
|
return Array.prototype.map.call(byteArray, function(byte) {
|
||||||
|
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
|
||||||
|
}).join('');
|
||||||
|
}
|
||||||
@@ -115,8 +115,7 @@
|
|||||||
@click="createNote(); switchMenu(); " icon="md-add"></Button>
|
@click="createNote(); switchMenu(); " icon="md-add"></Button>
|
||||||
|
|
||||||
<Button aria-label="crop" v-show="model.showDownloadText" type="error"
|
<Button aria-label="crop" v-show="model.showDownloadText" type="error"
|
||||||
style="border-radius: 0px;font-size: 24px;" @click="saveImage();switchMenu();"
|
style="border-radius: 0px;font-size: 24px;" @click="saveImage(); switchMenu();" icon="md-crop"></Button>
|
||||||
icon="md-crop"></Button>
|
|
||||||
|
|
||||||
<Button aria-label="download text" v-show="model.showDownloadText" type="error"
|
<Button aria-label="download text" v-show="model.showDownloadText" type="error"
|
||||||
style="border-radius: 0px;font-size: 24px;" @click="downLoadText(); switchMenu();"
|
style="border-radius: 0px;font-size: 24px;" @click="downLoadText(); switchMenu();"
|
||||||
@@ -231,12 +230,15 @@ export default {
|
|||||||
toTopState: false,
|
toTopState: false,
|
||||||
showMenuState: false,
|
showMenuState: false,
|
||||||
showHeaderShade: false,
|
showHeaderShade: false,
|
||||||
pageSession: '',
|
|
||||||
errorInfo: '',
|
errorInfo: '',
|
||||||
|
lastEditTime: 0,
|
||||||
|
backStoreTextInterval: null,
|
||||||
|
lastStoreCount: 0,
|
||||||
|
lastStoreTime: 0,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.pageSession = new Date().getTime();
|
this.editTime = new Date().getTime();
|
||||||
|
|
||||||
// read $route
|
// read $route
|
||||||
this.noteForm.key = this.$route.params.name;
|
this.noteForm.key = this.$route.params.name;
|
||||||
@@ -290,6 +292,10 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.lastStoreCount = this.noteForm.text.length;
|
||||||
|
this.lastEditTime = new Date().getTime();
|
||||||
|
this.lastStoreTime = this.lastEditTime;
|
||||||
|
|
||||||
this.bindCtrlAllEvent();
|
this.bindCtrlAllEvent();
|
||||||
this.bindToTopEvent();
|
this.bindToTopEvent();
|
||||||
|
|
||||||
@@ -310,12 +316,15 @@ export default {
|
|||||||
const someOtherEl = document.querySelector('#wrapper');
|
const someOtherEl = document.querySelector('#wrapper');
|
||||||
|
|
||||||
myObserver.observe(someOtherEl);
|
myObserver.observe(someOtherEl);
|
||||||
|
|
||||||
|
window.addEventListener('beforeunload', e => this.beforeunloadHandler(e))
|
||||||
},
|
},
|
||||||
updated() {
|
updated() {
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
},
|
},
|
||||||
destroyed() {
|
destroyed() {
|
||||||
|
window.removeEventListener('beforeunload', e => this.beforeunloadHandler(e))
|
||||||
},
|
},
|
||||||
computed: {},
|
computed: {},
|
||||||
watch: {},
|
watch: {},
|
||||||
@@ -352,7 +361,49 @@ export default {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let nowEditCount = this.noteForm.text.length;
|
||||||
|
let nowEditTime = new Date().getTime();
|
||||||
|
|
||||||
|
if (nowEditCount < 1024) {
|
||||||
setStoreText(this.noteForm, this.state, this.secret);
|
setStoreText(this.noteForm, this.state, this.secret);
|
||||||
|
this.lastStoreTime = nowEditTime;
|
||||||
|
this.lastStoreCount = nowEditCount;
|
||||||
|
} else {
|
||||||
|
if (null == this.backStoreTextInterval) {
|
||||||
|
this.backStoreTextInterval = window.setInterval(this.backStoreFunction(), 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.lastEditTime = nowEditTime;
|
||||||
|
},
|
||||||
|
backStoreFunction() {
|
||||||
|
let that = this;
|
||||||
|
return function () {
|
||||||
|
that.backStoreText(that);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
backStoreText(that) {
|
||||||
|
let nowEditCount = that.noteForm.text.length;
|
||||||
|
let nowEditTime = new Date().getTime();
|
||||||
|
if (Math.abs(nowEditCount - that.lastStoreCount) > 10) {
|
||||||
|
setStoreText(that.noteForm, that.state, that.secret);
|
||||||
|
that.lastStoreTime = that.lastEditTime;
|
||||||
|
that.lastStoreCount = nowEditCount;
|
||||||
|
} else {
|
||||||
|
if (nowEditTime - that.lastEditTime >= 1000 && nowEditTime - that.lastEditTime < 20000) {
|
||||||
|
if (that.lastEditTime != that.lastStoreTime) {
|
||||||
|
setStoreText(that.noteForm, that.state, that.secret);
|
||||||
|
that.lastStoreTime = that.lastEditTime;
|
||||||
|
that.lastStoreCount = nowEditCount;
|
||||||
|
}
|
||||||
|
} else if (nowEditTime - that.lastEditTime >= 20000) {
|
||||||
|
if (that.backStoreTextInterval != null) {
|
||||||
|
let ivl = that.backStoreTextInterval;
|
||||||
|
that.backStoreTextInterval = null;
|
||||||
|
window.clearInterval(ivl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// recordEventKup(event) {
|
// recordEventKup(event) {
|
||||||
// let tn = event.currentTarget.value;
|
// let tn = event.currentTarget.value;
|
||||||
@@ -392,7 +443,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.noteForm.text = event.currentTarget.value;
|
this.noteForm.text = event.currentTarget.value;
|
||||||
setStoreText(this.noteForm, this.state, this.secret);
|
this.recordText();
|
||||||
|
|
||||||
} else if (event.ctrlKey && (event.which == 13)) {
|
} else if (event.ctrlKey && (event.which == 13)) {
|
||||||
//save
|
//save
|
||||||
@@ -550,6 +601,9 @@ export default {
|
|||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
beforeunloadHandler() {
|
||||||
|
this.recordText();
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -336,7 +336,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
import { md5, unwrap } from "@/libs/secret";
|
import { md5, unwrap, convertUint8ArrayToHexString} from "@/libs/secret";
|
||||||
import { getStoreKey } from "@/api/lock";
|
import { getStoreKey } from "@/api/lock";
|
||||||
import { deleteNote, getNoteBlob } from "@/api/note";
|
import { deleteNote, getNoteBlob } from "@/api/note";
|
||||||
import storage from "@/libs/storage";
|
import storage from "@/libs/storage";
|
||||||
@@ -589,8 +589,9 @@ export default {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var bytes = new Uint8Array(e.target.result);
|
// let decoder = new TextDecoder();
|
||||||
let bytesString = bytes.join(",");
|
// let bytesString = decoder.decode(e.target.result);
|
||||||
|
let bytesString = convertUint8ArrayToHexString(new Uint8Array(e.target.result));
|
||||||
that.noteForm.text = unwrap(bytesString, that.secret.secretKey);
|
that.noteForm.text = unwrap(bytesString, that.secret.secretKey);
|
||||||
//that.noteForm.escapeText = getEscapeText(that.noteForm.text);
|
//that.noteForm.escapeText = getEscapeText(that.noteForm.text);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user