npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@youzanyun-fe/youzanyun-data-security

v0.0.2

Published

有赞云数据加密 NodeJS 版

Downloads

1

Readme

有赞云数据加密 NodeJS 版

npm 依赖安装

npm install @youzanyun-fe/youzanyun-data-security --save

示例

const DataSecurity = require('@youzanyun-fe/youzanyun-data-security');

(async () => {
  const clientId = '68ffaf8440a4babcde';
  const clientSecret = 'b0030740948e368c4ca21ed5d0b123456';
  const kdtId = 789456;
  const ds = new DataSecurity(clientId, clientSecret);

  // 加密
  const cipherText = await ds.encrypt(kdtId, '13012341234');
  const cipherText2 = await ds.encrypt(kdtId, '18812341234');
  // 解密
  const source = await ds.decrypt(kdtId, cipherText); // 13012341234
  // 解密并脱敏
  const decryptMaskResult = await ds.decryptMask(kdtId, cipherText, DataSecurity.MASK_TYPE.MOBILE); // 130****1234

  // 批量加密
  const encryptResult = await ds.batchEncrypt(kdtId, ['13012341234', '浙江省杭州市']); // {"13012341234": 'xxxxx', "浙江省杭州市": xxxxx}
  // 批量解密
  const mobiles = batchDecrypt(kdtId, [cipherText, cipherText2]);
  // 批量解密并脱敏
  const result = await ds.batchDecryptMask(
    kdtId,
    [cipherText, cipherText2],
    SecretClient.MASK_TYPE.BANK_CARD,
  );

  // 生成模糊搜索字符串
  const searchStr = await ds.generateEncryptSearchDigest(kdtId, cipherText);

  // 是否是密文
  const isCipher = DataSecurity.isEncrypt(cipherText); // true
  // 批量判断是否是密文
  const isCiphers = DataSecurity.isEncrypt([cipherText, cipherText2]); // true
})();

API

constructor()

构造器函数

参数说明

| 字段 | 类型 | 说明 | | ------------ | ------ | ------------ | | clientId | string | clientId | | clientSecret | string | clientSecret |

示例
const ds = new DataSecurity(clientId, clientSecret);

encrypt(kdtId, source)

加密方法,返回加密后的字符串

参数说明

| 字段 | 类型 | 说明 | | ------ | ------ | ------- | | kdtId | number | 店铺 id | | source | string | 明文 |

示例
const cipherText = await ds.encrypt(kdtId, '13012341234');
const cipherText2 = await ds.encrypt(kdtId, '18812341234');

batchEncrypt(kdtId, sources)

批量加密方法,返回一个 Object,key 为明文,value 为密文。

参数说明

| 字段 | 类型 | 说明 | | ------- | -------- | -------- | | kdtId | number | 店铺 id | | sources | string[] | 明文数组 |

示例
const encryptResult = await ds.batchEncrypt(kdtId, ['13012341234', '浙江省杭州市']); // {"13012341234": 'xxxxx', "浙江省杭州市": xxxxx}

decrypt(kdtId, cipherText)

解密方法,返回解密后的明文,传入明文时返回明文。tip: 解密失败会抛异常

参数说明

| 字段 | 类型 | 说明 | | ---------- | ------ | ------- | | kdtId | number | 店铺 id | | cipherText | string | 密文 |

示例
// 加密
const cipherText = await ds.encrypt(kdtId, '13012341234');
// 解密
const source = await ds.decrypt(kdtId, cipherText); // 13012341234

batchDecrypt(kdtId, cipherTexts)

批量解密,返回一个 Object,key 为密文,value 为明文。

参数说明

| 字段 | 类型 | 说明 | | ----------- | -------- | -------- | | kdtId | number | 店铺 id | | cipherTexts | string[] | 密文数组 |

示例
// 加密
const cipherText = await ds.encrypt(kdtId, '13012341234');
const cipherText2 = await ds.encrypt(kdtId, '18812341234');
// 批量解密
const mobiles = batchDecrypt(kdtId, [cipherText, cipherText2]);

decryptMask(kdtId, cipherText, type)

解密并脱敏,返回解密并脱敏后的明文。

参数说明

| 字段 | 类型 | 说明 | | ---------- | ------ | ------------------------------------- | | kdtId | number | 店铺 id | | cipherText | string | 密文 | | type | number | 脱敏类型 (参考文档最后的脱敏类型枚举) |

示例
// 加密
const cipherText = await ds.encrypt(kdtId, '13012341234');
// 解密并脱敏
const decryptMaskResult = await ds.decryptMask(kdtId, cipherText, DataSecurity.MASK_TYPE.MOBILE); // 130****1234

batchDecryptMask(kdtId, cipherTexts, type)

批量解密并脱敏,返回一个 Object,key 为密文,value 为解密并脱敏后的明文。

参数说明

| 字段 | 类型 | 说明 | | ----------- | -------- | ------------------------------------- | | kdtId | number | 店铺 id | | cipherTexts | string[] | 密文数组 | | type | number | 脱敏类型 (参考文档最后的脱敏类型枚举) |

示例
// 加密
const cipherText = await ds.encrypt(kdtId, '13012341234');
const cipherText2 = await ds.encrypt(kdtId, '18812341234');
// 批量解密并脱敏
const result = await ds.batchDecryptMask(
  kdtId,
  [cipherText, cipherText2],
  SecretClient.MASK_TYPE.BANK_CARD,
);

generateEncryptSearchDigest(kdtId, source)

生成模糊加密字符串, 支持部分搜索,返回一个结果字符串。

参数说明

| 字段 | 类型 | 说明 | | ------ | ------ | ------- | | kdtId | number | 店铺 id | | source | string | 明文 |

示例
// 加密
const cipherText = await ds.encrypt(kdtId, '13012341234');
// 生成模糊搜索字符串
const searchStr = await ds.generateEncryptSearchDigest(kdtId, cipherText);

static MASK_TYPE

静态属性,脱敏类型枚举定义

| 类型 | 类型说明 | 值 | | ------------ | -------- | --- | | ADDRESS | 地址 | 0 | | BANK_CARD | 银行卡号 | 1 | | NAME | 用户名 | 2 | | EMAIL | 邮箱地址 | 3 | | COMPANY_NAME | 企业名称 | 4 | | ID_CARD | 身份证号 | 5 | | MOBILE | 手机号码 | 6 |

示例
// 加密
const cipherText = await ds.encrypt(kdtId, '13012341234');
// 解密并脱敏
const decryptMaskResult = await ds.decryptMask(kdtId, cipherText, DataSecurity.MASK_TYPE.MOBILE); // 130****1234

static isEncrypt(cipherText)

判断输入是不是密文,返回 true/false。

示例
const cipherText = await ds.encrypt(kdtId, '13012341234');
const isCipher = DataSecurity.isEncrypt(cipherText); // true

static batchIsEncrypt(cipherTexts)

批量是否密文判断,返回 true/false。

示例
// 加密
const cipherText = await ds.encrypt(kdtId, '13012341234');
const cipherText2 = await ds.encrypt(kdtId, '18812341234');

const isCipher = DataSecurity.isEncrypt([cipherText, cipherText2]);