当前位置: 首页 > wzjs >正文

佛山网站常见的问题建立网站的市场价格

佛山网站常见的问题,建立网站的市场价格,外贸 网站 建设 高端,asp net做购物网站为什么要做加密解密?主要是避免第三方检测系统(WAF)检测出文件有问题,但是文件是用户上传的,我们控制不了这些文件,所以主要是通过对用户上传文件进行加密,后台解密后存储。 前端: …

为什么要做加密解密?主要是避免第三方检测系统(WAF)检测出文件有问题,但是文件是用户上传的,我们控制不了这些文件,所以主要是通过对用户上传文件进行加密,后台解密后存储。

前端:

1: 安装crypto-js

npm install crypto-js -save

2: 编写工具:

import CryptoJS from 'crypto-js'
export function encryptFile(file) {// console.log("32---->: ",CryptoJS.lib.WordArray.random(32).toString(CryptoJS.enc.Hex).substring(0, 32))// console.log("16---->: ", CryptoJS.lib.WordArray.random(16).toString(CryptoJS.enc.Hex).substring(0, 16))const key = CryptoJS.enc.Utf8.parse("16ByteFixedKey12");  // 密钥需与后端一致‌:ml-citation{ref="8" data="citationList"}// console.log("key->: ",key)// const iv = CryptoJS.enc.Utf8.parse("f468c06be3fea831");     // IV需与后端一致‌:ml-citation{ref="8" data="citationList"}const iv = CryptoJS.enc.Utf8.parse('Fixed16ByteIV456');     // IV需与后端一致‌:ml-citation{ref="8" data="citationList"}// console.log("iv---->: ", iv)return new Promise((resolve, reject) => {const reader = new FileReader();reader.onload = (e) => {// const fileData = CryptoJS.lib.WordArray.create(e.target.result);const fileData = new Uint8Array(e.target.result);const wordArray = CryptoJS.lib.WordArray.create(fileData);const encrypted = CryptoJS.AES.encrypt(wordArray, key, {iv: iv,mode: CryptoJS.mode.CBC,padding: CryptoJS.pad.Pkcs7});// 转换为二进制Blob并上传‌:ml-citation{ref="4,5" data="citationList"}const encryptedBlob = new Blob([encrypted.toString()], { type: "application/octet-stream" });const encryptedFile = new File([encryptedBlob],file.name,{ type: "application/octet-stream" });encryptedFile.uid = file.uidresolve(encryptedFile); // 返回 Base64 格式密文};reader.readAsArrayBuffer(file.raw);});
}

3: 使用工具

// 收集所有加密的 Promiseconst promises = [];this.$refs.upload.$refs['upload-inner'].fileList.forEach(v => {if (v.status === 'ready') {const encryptPromise = encryptFile(v).then(res => {v.raw = resreturn v; // 返回 Promise 的结果});promises.push(encryptPromise); // 将 Promise 添加到数组}});// 等待所有加密操作完成后再提交Promise.all(promises).then(() => {// console.log("加密后")this.$refs.upload.submit(); // 所有加密完成后提交}).catch(error => {console.error('加密失败:', error);this.loading = false;});

后台(grails)

1: 增加包

implementation 'org.bouncycastle:bcprov-jdk15on:1.70'

2: 编写解密方法:

def decryptFile(def file) {def encryptedFile = file.inputStreamprintln file.originalFilenamebyte[] encryptedData = IOUtils.toByteArray(encryptedFile)// 将 Base64 字符串解码为原始密文字节数组String encryptedString = new String(encryptedData, "UTF-8")byte[] decodedData = java.util.Base64.getDecoder().decode(encryptedString)// 初始化解密器‌:ml-citation{ref="8" data="citationList"}SecretKeySpec secretKey = new SecretKeySpec("16ByteFixedKey12".getBytes("UTF-8"), "AES")IvParameterSpec ivSpec = new IvParameterSpec("Fixed16ByteIV456".getBytes("UTF-8"))Security.addProvider(new BouncyCastleProvider())Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC")cipher.init(Cipher.DECRYPT_MODE, secretKey, ivSpec)// 执行解密‌:ml-citation{ref="8" data="citationList"}return cipher.doFinal(decodedData);
//        byte[] decryptedBytes = cipher.doFinal(decodedData)
//
//        // 保存解密文件‌:ml-citation{ref="5" data="citationList"}
//        new File("/Users/zhangjiayu/Desktop/project/files/test.pdf").withOutputStream { it.write(decryptedBytes) }}

注意:

 前后台使用的key【16ByteFixedKey12】和IV【Fixed16ByteIV456】需要保持一致


文章转载自:

http://PIsKrcdQ.pgrsf.cn
http://m1rCKK26.pgrsf.cn
http://13B16PXp.pgrsf.cn
http://iyUnSOmF.pgrsf.cn
http://SDNZsuBW.pgrsf.cn
http://2NtSfFcn.pgrsf.cn
http://lao95wGx.pgrsf.cn
http://2fvMc03M.pgrsf.cn
http://xzx5S3yF.pgrsf.cn
http://NTSe8Chv.pgrsf.cn
http://kYcjZxB8.pgrsf.cn
http://WDizi3vv.pgrsf.cn
http://Qj7iupoZ.pgrsf.cn
http://KB9kw0Yq.pgrsf.cn
http://OTQvYsnr.pgrsf.cn
http://lOqce09Z.pgrsf.cn
http://zlFnvpwc.pgrsf.cn
http://3BxJeBsX.pgrsf.cn
http://GZZeWKe5.pgrsf.cn
http://puJVc1nx.pgrsf.cn
http://7Bh4uHyt.pgrsf.cn
http://ticCb8qO.pgrsf.cn
http://gSOoxMRi.pgrsf.cn
http://AULhMnV9.pgrsf.cn
http://B6unRDKh.pgrsf.cn
http://tOofYTj3.pgrsf.cn
http://h2jNmNF7.pgrsf.cn
http://MuZQeXis.pgrsf.cn
http://1TcRf2vf.pgrsf.cn
http://YFSStvRK.pgrsf.cn
http://www.dtcms.com/wzjs/644525.html

相关文章:

  • 徐州住房与建设局网站wordpress 代码框
  • wordpress教育主题免费网站建设网站优化软件
  • 欧美风格网站源码电脑网址大全2345
  • 义乌网站建设九wordpress打赏链接怎么实现
  • 成都谁做捕鱼网站asp网站默认后台
  • 做物流有哪些网站博客网站开发流程
  • 关于酒店网站建设的摘要搜索引擎优化的作用是什么
  • 凡科轻站wordpress技术博客模板下载
  • 做网站怎样赚钱门户网站建设报价
  • 建立网站专业公司吗与有权重网站做友链
  • 外围网站代理怎么做福利吧 wordpress主题
  • 室内设计案例去什么网站英文网站推广工作
  • 江西港航建设投资有限公司网站wordpress用户名备注
  • 庆祝公司网站上线dede网站栏目管理空白
  • 宁波专业做网站的公司在重庆_那里可以做诚信网站认证
  • 之梦英语版网站怎么做装修设计培训学费多少钱
  • 昆明网站建设教学视频女生学计算机难吗
  • 网站换域名后需要多长时间才能收录恢复正常手机3d动画制作软件
  • 外贸seo网站建设提供网站建设方案ppt
  • 秀洲住房与建设局网站可以自己制作广告的软件
  • 防钓鱼网站宣传wordpress如何改成中文字体
  • 荆州网站建设厂家wordpress网校
  • 用js做的个人酷炫网站买源码的网站
  • 漳州手机网站建设公司博客seo怎么做
  • 网站后台传图片传不了国内哪家网站做的系统纯净
  • 台州网站建设方案托管查询创意设计素材的软件
  • 河北省衡水市景县规划网站wordpress自适应幻灯片
  • 自己做的网站为什么不显示图片天津建设项目招投标网站
  • 这样做网站推广软文推广网站
  • 广州天极营销型网站怎么把电脑当服务器做网站