@pagoda-tools/crypto-node
v1.0.1
Published
crypto-node 工具扩展功能
Downloads
11
Keywords
Readme
@pagoda-tools/crypto-node
服务端加解密工具
安装
@pagoda-tools/crypto-node
可通过npm
和yarn
获得:
# install npm
npm install @pagoda-tools/crypto-node -S
# install yarn
yarn add @pagoda-tools/crypto-node -S
用法
引入
import { PdBizDataCryptNode } from '@pagoda-tools/crypto-node';
初始化 pdBizDataCryptNode.js
import axios from 'axios';
// 服务端
const pdBizDataCryptNode = new PdBizDataCryptNode({
private_key: '申请得来的私钥,',
appId: '自定义应用ID,如:项目名 admin',
sessionKey: '自定义或申请来的密钥',
});
export default pdBizDataCryptNode;
加密与解密
import pdBizDataCryptNode from './pdBizDataCryptNode.js';
const data = { aaa: 123 };
// 数据加密
const { encryptedData, iv } = pdBizDataCryptNode.encrypt(data);
// 数据解密
const { aaa: a1 } = pdBizDataCryptNode.decrypt(encryptedData, iv);
// a1 === aaa ==> true