Skip to content

基于node.js crypto模块能够有选择的加解密 对象中的值

Notifications You must be signed in to change notification settings

fantasy9571/cryptoecb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

#cryptoecb 基于node.js 内置crypto模块 实现Object对象加解密

�示例:

//参数:
{   params: {
        name: '张三',
        sex: '男'
        phone: '13312345678',
        idcard: '300123201811263018',
      }, //必填
    key: 'secret key', //必填 �加密解密必须是相同的key 请保管好
    keyPattern:'',   //选填 默认加密对象中所有的键值 格式:'phone|idcard'
    negation: Bool  //�选填 默认为false, 作用:取反操作
}

##如何使用

npm i cryptoecb -S

1、加密encrypt

const cryptoecb = require('cryptoecb')

const key = '0fCTbJBOAWg1r9YiKV3UScMjdeX7GZPl'
const objPramas = {
    params: {
        name: '张三',
        sex: '男',
        phone: '13312345678',
        idcard: '300123201811263018',
      },
    key,
    keyPattern:'phone|idcard' 
}
const encryptResult = cryptoecb.encrypt(objPramas)
console.log(encryptResult)
{
    "name": "张三",
    "sex": "男",
    "phone": "6dd9388a4476276e48d784685899e660",
    "idcard": "fc39704898abcd602f9585aaf0c0862f84980d538b6d4df8bbee7f4c65c34422"
}

2、解密 decrypt


const objPramas = {
    params: encryptResult,
    key,
    keyPattern:'phone|idcard' 
}
const decryptRsult = cryptoecb.decrypt(objPramas)
console.log(decryptRsult)
{
    "name": "张三",
    "sex": "男",
    "phone": "13312345678",
    "idcard": "300123201811263018"
}

About

基于node.js crypto模块能够有选择的加解密 对象中的值

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published