This commit is contained in:
Jesse-Ma
2023-03-06 15:55:37 +08:00
parent 5a7b53b815
commit 8242885c50
3 changed files with 67 additions and 15 deletions

View File

@@ -21,7 +21,8 @@
"vue": "^2.7.14", "vue": "^2.7.14",
"vue-axios": "^3.5.2", "vue-axios": "^3.5.2",
"vue-i18n": "^8.28.2", "vue-i18n": "^8.28.2",
"vue-router": "^3.5.4" "vue-router": "^3.5.4",
"wasm-flate": "1.0.2-bundler"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.12.16", "@babel/core": "^7.12.16",

View File

@@ -26,8 +26,8 @@ const en = {
"100006": "Server Unavailable!", "100006": "Server Unavailable!",
"100011": "Empty Note!", "100011": "Empty Note!",
"100012": "Too Large, Beyond {0}!", "100012": "Too Large, Beyond {0}!",
"100013": "Repetitive submit!", "100013": "The address is used, Copy to a new address.",
"100014": "Modified Text!", "100014": "The text has been modified.",
"800001": "Repetitive Submit!", "800001": "Repetitive Submit!",
} }
}; };

View File

@@ -1,5 +1,7 @@
import CryptoJS from "crypto-js"; import CryptoJS from "crypto-js";
import pako from "pako"; import pako from "pako";
import {gzip_encode_raw,gzip_decode_raw} from 'wasm-flate';
/** /**
* @word 要加密的内容 * @word 要加密的内容
@@ -9,12 +11,12 @@ import pako from "pako";
export function wrap(text, secretKey) { export function wrap(text, secretKey) {
text = "FLAGNOTE#" + text; text = "FLAGNOTE#" + text;
let result = aesEncrypt(text, secretKey); let result = aesEncrypt(text, secretKey);
result = zip(result); result = noteZip(result);
return result; return result;
} }
export function unwrap(storeText, secretKey) { export function unwrap(storeText, secretKey) {
let result = unzip(storeText); let result = noteUnzip(storeText);
result = aesDecrypt(result, secretKey); result = aesDecrypt(result, secretKey);
if (result.startsWith("FLAGNOTE#")) { if (result.startsWith("FLAGNOTE#")) {
return result.substring(9); return result.substring(9);
@@ -41,6 +43,7 @@ export function aesEncrypt(word, keyWord) {
//解密 //解密
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, { let decrypt = CryptoJS.AES.decrypt(word, key, {
mode: CryptoJS.mode.ECB, mode: CryptoJS.mode.ECB,
@@ -49,28 +52,76 @@ export function aesDecrypt(word, keyWord) {
return CryptoJS.enc.Utf8.stringify(decrypt).toString(); return CryptoJS.enc.Utf8.stringify(decrypt).toString();
} }
//base64 encode
export function encode(text) { export function encode(text) {
return btoa(encodeURIComponent(text)); return Buffer.from(text, 'utf-8').toString('base64');
} }
//base64 decode
export function decode(text) { export function decode(text) {
return decodeURIComponent(atob(text)); return Buffer.from(text,'base64').toString('utf-8');
} }
export function unzip(text) { export function noteUnzip(text) {
let charData = text.split(",").map(function (x) { let charData = text.split(",").map(function (x) {
return parseInt(x); return parseInt(x);
}); });
let binData = new Uint8Array(charData); let binData = new Uint8Array(charData);
let data = pako.ungzip(binData); let data = unzip(binData);
//text = String.fromCharCode.apply(null, new Uint8Array(data)); text = String.fromCharCode.apply(null, new Uint8Array(data));
text = new Uint8Array(data).reduce(function (data, byte) {
return data + String.fromCharCode(byte);
}, "");
return text; return text;
} }
export function zip(text) { export function noteZip(text) {
text = pako.gzip(text, { to: "string" }); let encoder = new TextEncoder();
let data = encoder.encode(text);
text = zip(data);
return text; return text;
} }
function zip(data){
if(gzip_encode_raw){
return gzip_encode_raw(data);
}
return pako.gzip(data);
}
function unzip(data){
if(gzip_decode_raw){
return gzip_decode_raw(data);
}
return pako.ungzip(data);
}
// function convertWordArrayToUint8Array(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;
// }
// function convertUint8ArrayToWordArray(u8Array) {
// var words = [], i = 0, len = u8Array.length;
// while (i < len) {
// words.push(
// (u8Array[i++] << 24) |
// (u8Array[i++] << 16) |
// (u8Array[i++] << 8) |
// (u8Array[i++])
// );
// }
// return {
// sigBytes: words.length * 4,
// words: words
// };
// }