博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
前端 使用 crypto-js 对数据进行对称加密
阅读量:7230 次
发布时间:2019-06-29

本文共 1075 字,大约阅读时间需要 3 分钟。

传送门:

# crypto-js githubhttps://github.com/brix/crypto-js

 

demo1:

// 加载核心加密库var CryptoJS = require("crypto-js");// 加载des算法var tripledes = require("crypto-js/tripledes");// 开始加密,并且返回密文var ciphertext  = tripledes.encrypt("fuckyou", '123').toString();// 解密var plaintext  = tripledes.decrypt(ciphertext, '123').toString(CryptoJS.enc.Utf8)// 输出密文和解密后的内容console.log(ciphertext, plaintext)

 

demo2:

// 加载核心加密库var CryptoJS = require("crypto-js");function encrypt (message, key) {    var keyHex = CryptoJS.enc.Utf8.parse(key);     var encrypted = CryptoJS.DES.encrypt(message, keyHex, {        mode: CryptoJS.mode.ECB,        padding: CryptoJS.pad.Pkcs7    });    return {        key: keyHex,        value: encrypted.toString()    }}function decrypt (message, key) {    var plaintext = CryptoJS.DES.decrypt(message, key, {        mode: CryptoJS.mode.ECB,        padding: CryptoJS.pad.Pkcs7    })    return plaintext.toString(CryptoJS.enc.Utf8)}var a = encrypt('mssage123', '123');var b = decrypt(a.value, a.key);console.log(a.value.length)

 

转载于:https://www.cnblogs.com/CyLee/p/7216988.html

你可能感兴趣的文章
Android 自定义RadioButton的样式
查看>>
bzoj 3456 城市规划——分治FFT / 多项式求逆 / 多项式求ln
查看>>
bzoj1042硬币购物
查看>>
(3)pyspark----dataframe观察
查看>>
MFC 使用位图按钮,并且设置按钮的鼠标悬停效果
查看>>
ceph存储之查找对象
查看>>
IE7下浮动(float)层不能实现环绕的问题
查看>>
LeetCode 【Single Number I II III】
查看>>
BOOL类型和引用,三目运算符
查看>>
rocketMq概念介绍
查看>>
Google推出iOS功能性UI测试框架EarlGrey
查看>>
busybox filesystem ts_config: No such file or directory
查看>>
Unity 3D第三人称视角、用途广泛限定角度(视角不能360度翻转)
查看>>
Spreading the Wealth uva 11300
查看>>
Eclipse 报java.lang.UnsupportedClassVersionError: ("yourclass") bad major version at offset=6
查看>>
快读快输板子
查看>>
vue中父组件给子组件额外添加参数
查看>>
分片上传
查看>>
网络编程初识和socket套接字
查看>>
什么是构造函数?它和普通函数的区别?
查看>>