You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
1.8 KiB
JavaScript
76 lines
1.8 KiB
JavaScript
export { fileHash } from './fileHash'
|
|
|
|
import CryptoJS from 'crypto-js/crypto-js'
|
|
|
|
import { encrypt, decrypt } from '../jsencrypt'
|
|
|
|
|
|
const AESKey = "d34xsfljkwSD}2cv32$#%dfdgvcJH{PIOPeopir1KSHD"
|
|
|
|
/**
|
|
* Base64编码
|
|
* @param {String} str
|
|
* @returns
|
|
*/
|
|
const Base64Encode = (str) => CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(str))
|
|
|
|
/**
|
|
* Base64解码
|
|
* @param {String} str
|
|
* @returns
|
|
*/
|
|
const Base64Decode = (str) => CryptoJS.enc.Utf8.stringify(CryptoJS.enc.Base64.parse(str))
|
|
|
|
/**
|
|
* 消息摘要md5加密
|
|
* @param {String} str
|
|
* @returns
|
|
*/
|
|
const md5 = (str) => CryptoJS.enc.Hex.stringify(CryptoJS.MD5(str))
|
|
|
|
/**
|
|
* 消息摘要sha256加密
|
|
* @param {String} str
|
|
* @returns
|
|
*/
|
|
const sha256 = (str) => CryptoJS.enc.Hex.stringify(CryptoJS.SHA256(str))
|
|
|
|
|
|
/**
|
|
* 对称加密AES
|
|
* @param {String} str
|
|
* @returns
|
|
*/
|
|
const aesEncrypt = (str) => CryptoJS.AES.encrypt(str, AESKey).toString()
|
|
/**
|
|
* 对称解密AES
|
|
* @param {String} str
|
|
* @returns
|
|
*/
|
|
const aesDecrypt = (str) => CryptoJS.AES.decrypt(str, AESKey).toString(CryptoJS.enc.Utf8)
|
|
|
|
export { CryptoJS, Base64Encode, Base64Decode, md5, sha256, encrypt, decrypt, aesEncrypt, aesDecrypt }
|
|
|
|
|
|
// let str = "https://evoai.cn"
|
|
// let strEncode = Base64Encode(str)
|
|
// console.debug("Base64Encode", strEncode)
|
|
// console.debug("Base64Decode", Base64Decode(strEncode))
|
|
|
|
// console.debug("md5", md5(str))
|
|
// console.debug("sha256", sha256(str))
|
|
|
|
// strEncode = encrypt(str);
|
|
// console.debug("encrypt", strEncode)
|
|
|
|
// console.debug("decrypt", decrypt(strEncode))
|
|
|
|
// strEncode = aesEncrypt(str)
|
|
// console.debug("aesEncrypt", strEncode)
|
|
// console.debug("aesDecrypt", aesDecrypt(strEncode))
|
|
|
|
// console.debug("Hex.stringify",Hex.stringify(str));
|
|
// console.debug("Hex.parse",Hex.parse(Hex.stringify(str)));
|
|
// var words = CryptoJS.enc.Base64.parse("SGVsbG8sIFdvcmxkIQ==");
|
|
// console.debug(words)
|