前端怎么对接口数据进行加密

1594
2021/1/18 16:33:40
栏目: 网络安全
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

前端怎么对接口数据进行加密

在前端中使用AES对接口数据进行加密的方法

前端代码如下:

var aesUtil = {

//获取key,

genKey : function (length = 16) {

let random = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

let str = "";

for (let i = 0; i < length; i++) {

str = str + random.charAt(Math.random() * random.length)

}

return str;

},

//加密

encrypt : function (plaintext,key) {

if (plaintext instanceof Object) {

//JSON.stringify

plaintext = JSON.stringify(plaintext)

}

let encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(plaintext), CryptoJS.enc.Utf8.parse(key), {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});

return encrypted.toString();

}

};

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: 数据库密码信息加密方式有哪些