一、Node实现数据加密
1、加密的分类
(1)、对称加密:也称为单密钥加密.同一个密钥进行加密和解密
(2)、非对称加密:有两把钥匙(公钥和私钥)
(3)、摘要算法:把任意长度的输入,根据算法生成一串固定长度的伪随机数(没有密钥,加密过程是不可逆的)
2、MD5(摘要算法)在Node的使用方法
2.1、安装crypto模块
npm install crypto
2.2、使用crypto.createHash(‘md5’)创建加密对象
2.3、使用加密对象的update(明文)进行加密,然后调用digest(‘hex’)返回定长的十六进制字符串
3、演示:对用户的注册密码进行加密后存入数据库
3.1、安装模块
3.2、创建数据库连接配置对象的文件
//1、导入squelize模块
const Sequelize = require('sequelize')
//2、配置数据库连接对象
const sqllize =new Sequelize('mvc','root','qazzaq123',{
host:'localhost',
post:3306,
dialect:'mysql',
pool:{
//数据库连接池
max:10,
min:3,
idle:10000
}
})
//3、导出数据库的配置对象
module.exports = sqllize
3.3、创建模型
const Sequelize = require('sequelize')
const dqldemo = require('../seq')
const AdminModel = dqldemo.define('admins', {
Id: {
type: Sequelize.INTEGER,
primaryKey: true, // 主键
autoIncrement: true, //自增
field: 'id' //对应列名
},
userName: {
type: Sequelize.STRING,
allowNull: false, //不能为空
field: 'username'
},
userPwd: {
type: Sequelize.STRING,
field