0
点赞
收藏
分享

微信扫一扫

AES对称加密

Java架构领域 2021-09-22 阅读 79
日记本

AES加解密流程:

  • 密钥

对称加密算法与非对称加密算法的区别

  • 对称加密算法
  • 非对称加密算法

像https就是用非对称密钥协商出对称密钥,再用对称密钥来加密业务数据

如:
利用node.js或者webpack plugin 在打包时,进行js文件内容的加密打包处理

移动端执行逻辑

const crypto = require("crypto");
const CryptoJs = require('crypto-js')
// 哈希算法
const hash = crypto.createHash("md5");
// hmac算法
const hmac = crypto.createHmac("sha256", "key");
hmac.update("hello world");
console.log(hmac.digest("hex"));

hash.update("hello world");
console.log(hash.digest("hex"));
// AES对称加密算法
// encrypt
let cipherText = CryptoJs.AES.encrypt('hello world', 'key123').toString()
console.log(cipherText)
console.log('-----加密串-----')
const bytes = CryptoJs.AES.decrypt(cipherText, 'key123')
const originalText = bytes.toString(CryptoJs.enc.Utf8)
console.log(originalText)
console.log('------解密串-----')

PS:在前端常见的加密方式中AES很少使用,因为相对于非对称的RSA安全性很低,AES是典型的对称加密,密钥就在前端源码里(注意在信息保护中,完整性远远比机密性更重要。如果得到的信息是篡改、重放的,那你机密性没有多大用处)
https基本原理,也是用非对称密钥协商出对称密钥,再用对称密钥来加密业务数据

源作者:昭光
链接:https://juejin.cn/post/6901923757594509325

举报

相关推荐

0 条评论