Add files via upload
This commit is contained in:
@@ -1,49 +1,45 @@
|
||||
import {zip, aesEncrypt} from '../libs/secret'
|
||||
import { wrap } from "@/libs/secret";
|
||||
import storage from "@/libs/storage";
|
||||
import {getSecretKey} from "@/api/lock";
|
||||
import escapeHtml from "escape-html";
|
||||
|
||||
export function setStoreText(noteForm, secret, password) {
|
||||
let text = noteForm.text;
|
||||
export function setStoreText(noteForm, state, secret) {
|
||||
let text = noteForm.text;
|
||||
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
let storeText = "";
|
||||
if (text) {
|
||||
storeText = wrap(text, secret.secretKey);
|
||||
}
|
||||
|
||||
if (!password) {
|
||||
password = "";
|
||||
}
|
||||
|
||||
text = "FLAGNOTE#" + text;
|
||||
|
||||
let secretKey = getSecretKey(noteForm.key, password);
|
||||
let storeText = aesEncrypt(text, secretKey);
|
||||
storeText = zip(storeText);
|
||||
|
||||
let lock = 0;
|
||||
if (password) {
|
||||
lock = 1;
|
||||
}
|
||||
|
||||
|
||||
storage.local.setText(secret.storeKey + '.text', lock + '|' + secret.cipher + '|0|'+ noteForm.initTime+'|' + storeText);
|
||||
storage.local.setText(
|
||||
secret.storeKey,
|
||||
state.lock +
|
||||
"|" +
|
||||
secret.cipher +
|
||||
"|" +
|
||||
state.commited +
|
||||
"|" +
|
||||
state.initTime +
|
||||
"|" +
|
||||
storeText
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export function clearStoreText(key) {
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
storage.local.delete(key);
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
storage.local.delete(key);
|
||||
}
|
||||
|
||||
|
||||
export function getEscapeText(text) {
|
||||
let textEscape = escapeHtml(text);
|
||||
textEscape = textEscape.replace(new RegExp(' ','gm'), " ");
|
||||
textEscape = textEscape.replace(new RegExp('\\r\\n','gm'), "<br/>");
|
||||
textEscape = textEscape.replace(new RegExp('\\r','gm'), "<br/>");
|
||||
textEscape = textEscape.replace(new RegExp('\\n','gm'), "<br/>");
|
||||
textEscape = textEscape.replace(new RegExp('\\t','gm'), "<pre class=\"tab_pre\">	</pre>");
|
||||
return textEscape;
|
||||
let textEscape = escapeHtml(text);
|
||||
textEscape = textEscape.replace(new RegExp(" ", "gm"), " ");
|
||||
textEscape = textEscape.replace(new RegExp("\\r\\n", "gm"), "<br/>");
|
||||
textEscape = textEscape.replace(new RegExp("\\r", "gm"), "<br/>");
|
||||
textEscape = textEscape.replace(new RegExp("\\n", "gm"), "<br/>");
|
||||
textEscape = textEscape.replace(
|
||||
new RegExp("\\t", "gm"),
|
||||
'<pre class="tab_pre">	</pre>'
|
||||
);
|
||||
return textEscape;
|
||||
}
|
||||
|
||||
@@ -1,57 +1,77 @@
|
||||
import CryptoJS from 'crypto-js'
|
||||
import pako from 'pako'
|
||||
import CryptoJS from "crypto-js";
|
||||
import pako from "pako";
|
||||
|
||||
/**
|
||||
* @word 要加密的内容
|
||||
* @keyWord String 服务器随机返回的关键字
|
||||
* */
|
||||
|
||||
export function wrap(text, secretKey) {
|
||||
text = "FLAGNOTE#" + text;
|
||||
let result = aesEncrypt(text, secretKey);
|
||||
result = zip(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
export function unwrap(storeText, secretKey) {
|
||||
let result = unzip(storeText);
|
||||
result = aesDecrypt(result, secretKey);
|
||||
if (result.startsWith("FLAGNOTE#")) {
|
||||
return result.substring(9);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//加密
|
||||
export function md5(word, keyWord = 'F1agn0te') {
|
||||
let srcWords = CryptoJS.enc.Utf8.parse(word + '_' + keyWord);
|
||||
let encrypted = CryptoJS.MD5(srcWords);
|
||||
return encrypted.toString();
|
||||
export function md5(word, keyWord = "F1agn0te") {
|
||||
let srcWords = CryptoJS.enc.Utf8.parse(word + "_" + keyWord);
|
||||
let encrypted = CryptoJS.MD5(srcWords);
|
||||
return encrypted.toString();
|
||||
}
|
||||
|
||||
//加密
|
||||
export function aesEncrypt(word, keyWord) {
|
||||
let key = CryptoJS.enc.Utf8.parse(keyWord);
|
||||
let srcWords = CryptoJS.enc.Utf8.parse(word);
|
||||
let encrypted = CryptoJS.AES.encrypt(srcWords, key, {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7});
|
||||
return encrypted.toString();
|
||||
let key = CryptoJS.enc.Utf8.parse(keyWord);
|
||||
let srcWords = CryptoJS.enc.Utf8.parse(word);
|
||||
let encrypted = CryptoJS.AES.encrypt(srcWords, key, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7,
|
||||
});
|
||||
return encrypted.toString();
|
||||
}
|
||||
|
||||
//解密
|
||||
export function aesDecrypt(word, keyWord) {
|
||||
let key = CryptoJS.enc.Utf8.parse(keyWord);
|
||||
let decrypt = CryptoJS.AES.decrypt(word, key, {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7});
|
||||
return CryptoJS.enc.Utf8.stringify(decrypt).toString()
|
||||
let key = CryptoJS.enc.Utf8.parse(keyWord);
|
||||
let decrypt = CryptoJS.AES.decrypt(word, key, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7,
|
||||
});
|
||||
return CryptoJS.enc.Utf8.stringify(decrypt).toString();
|
||||
}
|
||||
|
||||
export function encode(text) {
|
||||
return btoa(encodeURIComponent(text))
|
||||
return btoa(encodeURIComponent(text));
|
||||
}
|
||||
|
||||
export function decode(text) {
|
||||
return decodeURIComponent(atob(text))
|
||||
return decodeURIComponent(atob(text));
|
||||
}
|
||||
|
||||
export function unzip(text) {
|
||||
let charData = text.split(',').map(function (x) {
|
||||
return parseInt(x)
|
||||
});
|
||||
let binData = new Uint8Array(charData);
|
||||
let data = pako.ungzip(binData);
|
||||
//text = String.fromCharCode.apply(null, new Uint8Array(data));
|
||||
text = new Uint8Array(data).reduce(function (data, byte) {
|
||||
return data + String.fromCharCode(byte);
|
||||
}, '');
|
||||
return text;
|
||||
let charData = text.split(",").map(function (x) {
|
||||
return parseInt(x);
|
||||
});
|
||||
let binData = new Uint8Array(charData);
|
||||
let data = pako.ungzip(binData);
|
||||
//text = String.fromCharCode.apply(null, new Uint8Array(data));
|
||||
text = new Uint8Array(data).reduce(function (data, byte) {
|
||||
return data + String.fromCharCode(byte);
|
||||
}, "");
|
||||
return text;
|
||||
}
|
||||
|
||||
export function zip(text) {
|
||||
text = pako.gzip(text, {to: 'string'});
|
||||
return text;
|
||||
text = pako.gzip(text, { to: "string" });
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
export function isWeixin(){
|
||||
var useragent = navigator.userAgent;
|
||||
if (useragent.match(/MicroMessenger/i) == 'MicroMessenger') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isIE() {
|
||||
if (navigator.userAgent.match(/msie/) != null || navigator.userAgent.match(/trident/) != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function getNoteUrl(key){
|
||||
return "https://flagnote.com/" + key;
|
||||
export function isWeixin(){
|
||||
var useragent = navigator.userAgent;
|
||||
if (useragent.match(/MicroMessenger/i) == 'MicroMessenger') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isIE() {
|
||||
if (navigator.userAgent.match(/msie/) != null || navigator.userAgent.match(/trident/) != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function getNoteUrl(key){
|
||||
return "https://flagnote.com/" + key;
|
||||
}
|
||||
Reference in New Issue
Block a user