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

我做网站价格完整的网站开发流程

我做网站价格,完整的网站开发流程,淘宝卖家中心网页版,织梦小说网站模板下载地址AES-CBC HMAC-SHA256 加密验证方案#xff0c;下面是该方案二等 优点 与 缺点 表格#xff0c;适用于文档、评审或技术选型说明。 ✅ 优点表格#xff1a;AES-CBC HMAC-SHA256 加密验证方案 类别优点说明#x1f510; 安全性使用 AES-CBC 对称加密使用 AES-128-CBC 是可…AES-CBC HMAC-SHA256 加密验证方案下面是该方案二等 优点 与 缺点 表格适用于文档、评审或技术选型说明。 ✅ 优点表格AES-CBC HMAC-SHA256 加密验证方案 类别优点说明 安全性使用 AES-CBC 对称加密使用 AES-128-CBC 是可靠且广泛接受的对称加密方式。随机生成 IV每次加密生成新的 IV有效防止密文重放与模式识别。HMAC-SHA256 签名增强完整性校验防止中间人篡改密文。加密前先签名验证防止不合法密文触发解密报错或被利用。 灵活性签名算法可切换支持从 HMAC-SHA256 切换为其他如 SHA-512。密钥可由 token 派生动态生成密钥便于用户级安全控制。前端跨平台适用适用于 Web、小程序、移动端等多平台前端环境。 可部署性可嵌入代理层Nginx Lua 可提前拦截无效请求节省后端资源。 多语言兼容Node.js、Python、Lua 等实现简单支持常见语言和平台易于团队协作与系统整合。 ❌ 缺点表格AES-CBC HMAC 签名方案的局限 类别缺点说明⚙️ 实现复杂度实现逻辑较多需要额外编码 IV 管理、HMAC 签名、前后端一致性等细节。 重放防护默认无时间戳或 nonce重放攻击不可防需要自行引入 timestamp nonce 参数。 密钥依赖密钥动态性带来兼容问题一旦 token 失效或更换旧数据将无法解密。 数据随机访问不支持局部解密AES-CBC 是块加密不能随机访问或解密数据片段。 不适合长期缓存密文随机性增加校验复杂度每次加密结果不同不适合用于长期静态存储的校验场景。 补充建议可选扩展 增强点建议防重放在签名前加上时间戳 nonce 字段防止多次使用旧数据加密模式升级可考虑迁移到 AES-GCM天然支持认证AEAD秘钥管理密钥建议动态派生如基于用户会话、JWT claims 等 下面是该方案的实现详细代码 ✅ 前端 JavaScriptfrontend.js // frontend.js // 前端使用 AES-CBC 加密 HMAC-SHA256 签名 import aesjs from aes-js; import CryptoJS from crypto-js;function aaa(token) {return aesjs.utils.utf8.toBytes(token.padEnd(16, 0).slice(0, 16)); }function generateRandomIV() {let iv new Uint8Array(16);window.crypto.getRandomValues(iv);return iv; }function getHmacSHA256(keyBytes, messageHex) {const keyHex CryptoJS.enc.Hex.parse(aesjs.utils.hex.fromBytes(keyBytes));const hmac CryptoJS.HmacSHA256(messageHex, keyHex);return hmac.toString(CryptoJS.enc.Hex); }function encryptWithMac(token, plaintext) {const key aaa(token);const iv generateRandomIV();const textBytes aesjs.utils.utf8.toBytes(plaintext);const padded aesjs.padding.pkcs7.pad(textBytes);const aesCbc new aesjs.ModeOfOperation.cbc(key, iv);const encryptedBytes aesCbc.encrypt(padded);const ivHex aesjs.utils.hex.fromBytes(iv);const ciphertextHex aesjs.utils.hex.fromBytes(encryptedBytes);const fullDataHex ivHex ciphertextHex;const mac getHmacSHA256(key, fullDataHex);return {data: fullDataHex,mac: mac}; }const token abc123; const msg hello world; const result encryptWithMac(token, msg); console.log(JSON.stringify(result)); ✅ Node.js 后端验证backend_node.js // backend_node.js const crypto require(crypto);function deriveKey(token) {return Buffer.from(token.padEnd(16, 0).slice(0, 16)); }function verifyEncryptedData(token, dataHex, macHex) {const key deriveKey(token);const iv Buffer.from(dataHex.slice(0, 32), hex);const ciphertext Buffer.from(dataHex.slice(32), hex);// 验证 HMACconst hmac crypto.createHmac(sha256, key);hmac.update(dataHex);const expectedMac hmac.digest(hex);if (expectedMac ! macHex) {throw new Error(MAC 验证失败);}// 解密const decipher crypto.createDecipheriv(aes-128-cbc, key, iv);decipher.setAutoPadding(true);let decrypted decipher.update(ciphertext, null, utf8);decrypted decipher.final(utf8);return decrypted; }// 示例 const token abc123; const { data, mac } JSON.parse(/* 前端结果 */ {data: ..., mac: ...});try {const plaintext verifyEncryptedData(token, data, mac);console.log(解密成功:, plaintext); } catch (e) {console.error(e.message); }✅ Python 后端验证backend_python.py # backend_python.py from Crypto.Cipher import AES from Crypto.Hash import HMAC, SHA256 from binascii import unhexlifydef derive_key(token: str) - bytes:return token.ljust(16, 0)[:16].encode()def verify_encrypted_data(token, data_hex, mac_hex):key derive_key(token)iv unhexlify(data_hex[:32])ciphertext unhexlify(data_hex[32:])# 验证 HMACh HMAC.new(key, digestmodSHA256)h.update(data_hex.encode())try:h.hexverify(mac_hex)except ValueError:raise ValueError(MAC 验证失败)# 解密cipher AES.new(key, AES.MODE_CBC, iv)padded cipher.decrypt(ciphertext)pad_len padded[-1]return padded[:-pad_len].decode()# 示例 token abc123 data ... # 前端 data mac ... # 前端 mactry:print(解密成功:, verify_encrypted_data(token, data, mac)) except Exception as e:print(失败:, e)✅ Nginx Lua (OpenResty)aes_verify.lua -- aes_verify.lua local aes require resty.aes local hmac require resty.hmac local str require resty.string local cjson require cjsonngx.req.read_body() local body ngx.req.get_body_data() local json cjson.decode(body) local data json.data local mac json.mac local token ngx.var.http_authorization:sub(8)local key token .. string.rep(0, 16 - #token) key key:sub(1, 16)local hmac_obj hmac:new(key, hmac.ALGOS.SHA256) hmac_obj:update(data) local expected_mac str.to_hex(hmac_obj:final())if expected_mac ~ mac thenngx.status 401ngx.say(MAC 验证失败)return ngx.exit(401) endlocal iv str.to_hex(data:sub(1, 32)) local cipher data:sub(33) local aes_cbc aes:new(key, nil, aes.cipher(128, cbc), { iv iv }) local decrypted aes_cbc:decrypt(str.from_hex(cipher)) local pad string.byte(decrypted:sub(-1)) decrypted decrypted:sub(1, -pad-1)ngx.say(验证通过原文: , decrypted)配置片段 location /api/secure-data {content_by_lua_file /etc/nginx/lua/aes_verify.lua;proxy_pass http://backend_service; }
http://www.zqtcl.cn/news/896546/

相关文章:

  • 网站开发甘特图网站是别人做的域名自己怎么续费
  • 如何查询网站是否备案江苏省句容建设局网站
  • 中国商业网点建设开发中心官方网站天津中小企业网站制作
  • 莱芜网站建设及优化云开发小程序源码
  • 珠海商城网站学校建网站
  • 自己网站如何做关键词排名网站配色网
  • 做二手物资哪个网站好江苏大汉建设实业集团网站
  • j2ee 建设简单网站Wordpress 导航条样式
  • 创客贴网页设计网站企业局域网
  • 深圳哪里网站制作云南建设网站首页
  • 赤峰做网站哪家好岳阳网站设计u
  • 腾讯云10g数字盘做网站够么网站开元棋牌怎么做app
  • 天津网站建设信息科技有限公司门户网站开发公司排名
  • 优秀策划设计网站jsp mysql开发网站开发
  • 深圳做微信网站建设我爱水煮鱼 wordpress
  • 企业网站推广是不是必要的蓝色网站建设
  • 浙江企业响应式网站建设网站建设 找vx cp5173
  • nodejs做的网站音乐网站制作教程
  • 怎么利用网站做外链接阿里云网站部署
  • 做学校网站简述网站的制作步骤
  • 怎样让网站响应式推广策划案
  • 网站开发 面试 适当吹牛网站文件命名规则
  • 河北省建设中心网站图片分享网站源码
  • 工信部网站备案修改个人求职网站怎么做
  • 关于建设公司网站的申请宁波网站制作出售
  • 织梦电影网站免费模板网站域名asia是
  • 顺德中小企业网站建设宁乡市建设局网站
  • 静态网页模板 网站模板兰州做网站价格
  • 吕梁推广型网站建设godaddy托管 wordpress
  • 什么网站百度收录好珠海哪里做网站的