use wasm
This commit is contained in:
@@ -21,7 +21,8 @@
|
||||
"vue": "^2.7.14",
|
||||
"vue-axios": "^3.5.2",
|
||||
"vue-i18n": "^8.28.2",
|
||||
"vue-router": "^3.5.4"
|
||||
"vue-router": "^3.5.4",
|
||||
"wasm-flate": "1.0.2-bundler"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.12.16",
|
||||
|
||||
@@ -26,8 +26,8 @@ const en = {
|
||||
"100006": "Server Unavailable!",
|
||||
"100011": "Empty Note!",
|
||||
"100012": "Too Large, Beyond {0}!",
|
||||
"100013": "Repetitive submit!",
|
||||
"100014": "Modified Text!",
|
||||
"100013": "The address is used, Copy to a new address.",
|
||||
"100014": "The text has been modified.",
|
||||
"800001": "Repetitive Submit!",
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import CryptoJS from "crypto-js";
|
||||
import pako from "pako";
|
||||
import {gzip_encode_raw,gzip_decode_raw} from 'wasm-flate';
|
||||
|
||||
|
||||
/**
|
||||
* @word 要加密的内容
|
||||
@@ -9,12 +11,12 @@ import pako from "pako";
|
||||
export function wrap(text, secretKey) {
|
||||
text = "FLAGNOTE#" + text;
|
||||
let result = aesEncrypt(text, secretKey);
|
||||
result = zip(result);
|
||||
result = noteZip(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
export function unwrap(storeText, secretKey) {
|
||||
let result = unzip(storeText);
|
||||
let result = noteUnzip(storeText);
|
||||
result = aesDecrypt(result, secretKey);
|
||||
if (result.startsWith("FLAGNOTE#")) {
|
||||
return result.substring(9);
|
||||
@@ -41,6 +43,7 @@ export function aesEncrypt(word, keyWord) {
|
||||
|
||||
//解密
|
||||
export function aesDecrypt(word, keyWord) {
|
||||
|
||||
let key = CryptoJS.enc.Utf8.parse(keyWord);
|
||||
let decrypt = CryptoJS.AES.decrypt(word, key, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
@@ -49,28 +52,76 @@ export function aesDecrypt(word, keyWord) {
|
||||
return CryptoJS.enc.Utf8.stringify(decrypt).toString();
|
||||
}
|
||||
|
||||
//base64 encode
|
||||
export function encode(text) {
|
||||
return btoa(encodeURIComponent(text));
|
||||
return Buffer.from(text, 'utf-8').toString('base64');
|
||||
}
|
||||
|
||||
//base64 decode
|
||||
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) {
|
||||
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);
|
||||
}, "");
|
||||
let data = unzip(binData);
|
||||
text = String.fromCharCode.apply(null, new Uint8Array(data));
|
||||
return text;
|
||||
}
|
||||
|
||||
export function zip(text) {
|
||||
text = pako.gzip(text, { to: "string" });
|
||||
export function noteZip(text) {
|
||||
let encoder = new TextEncoder();
|
||||
let data = encoder.encode(text);
|
||||
text = zip(data);
|
||||
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
|
||||
// };
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user