web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

nodejs如何利用3DES加密解密

408 ℃
     

nodejs如何利用3DES进行加密解密,下面web建站小编给大家简单介绍一下!

安装脚手架

npm install crypto

生成密钥

const crypto = require('crypto');
 
const key = crypto.randomBytes(24);
console.log(key.toString('hex'));

加密数据

const crypto = require('crypto');

const key = crypto.randomBytes(24);
const text = 'Hello, world!';
 
const cipher = crypto.createCipheriv('des-ede3', key, '');
let encrypted = cipher.update(text, 'utf8', 'hex');
encrypted += cipher.final('hex');
console.log(encrypted);

解密数据

const crypto = require('crypto');
 
const key = crypto.randomBytes(24);
const text = 'Hello, world!';
 
const cipher = crypto.createCipheriv('des-ede3', key, '');
let encrypted = cipher.update(text, 'utf8', 'hex');
encrypted += cipher.final('hex');
console.log(encrypted);
 
const decipher = crypto.createDecipheriv('des-ede3', key, '');
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
decrypted += decipher.final('utf8');
console.log(decrypted);

nodejs最常用加密方式有哪些

标签: 3DES加密, 3DES解密, crypto

上面是“nodejs如何利用3DES加密解密”的全面内容,想了解更多关于 nodejs 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_4503.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > nodejs
本文共计815个字,预计阅读时长6分钟
生活小工具,收录了80多款小工具
上一篇: 推荐一款免费商用的斜体创意字体——字魂扁桃体
下一篇: 推荐一款充满古雅之风的免费字体——问藏书房字体
x 打工人ai神器