Add files via upload
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user