🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@sunmi/secure

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sunmi/secure

functions for security

latest
npmnpm
Version
1.1.0
Version published
Maintainers
3
Created
Source

简介

用于处理约定的加解密操作,包括密码加密,请求体封装,des加解密等

支持 browser端 和 node端 使用

安装

通过npm:

npm i @sunmi/secure

浏览器引用:

<!-- 需要依赖crypto-js -->
<script src="/path/to/crypto-js.js" />
<script src="/path/to/@sunmi/secure/dist/index.js" />
<!-- 通过全局对象 Secure 使用 -->

使用

初始化实例

import Secure from '@sunmi/secure';
// 初始化实例
const secure = new Secure({
  md5Key: '', // md5加密key
  desKey: '', // des加密key
  desIv: '',  // des加密iv
  isEncrypted: 1 // 是否开启参数加密,1|0,开启后请求体中的参数会进行加密
});

// des加密
secure.encrypt('message')

实例提供的方法列表

Secure
  |- encrypt
  |- decrypt
  |- encodePassword
  |- resolveBody
  |- paramsEncode
  |- paramsDecode

secure.encrypt

des加密

参数

  • 待加密字符串

返回

  • 加密字符串
secure.encrypt(string)

secure.decrypt

des解密

参数

  • 已加密字符串

返回

  • 解密字符串
secure.decrypt(string)

secure.encodePassword

密码字符串加密

参数

  • 密码字符串

返回

  • 加密字符串
secure.encodePassword(string)

secure.resolveBody

request请求体包装处理

参数

  • params 请求参数对象
  • opts 附加处理项,对象
    • opts.contentType 请求体类型,取值['multipart/form-data' | 'application/x-www-urlencoded']
    • opts.extraBody 额外的body参数,会添加到请求体中

返回

  • 加密字符串
secure.resolveBody(params, opts)

secure.paramsEncode

请求体params字段加密

参数

  • 参数对象

返回

  • 加密字符串
secure.paramsEncode(params)

secure.paramsDecode

请求体params字段解密

参数

  • 加密字符串

返回

  • 参数对象
secure.paramsDecode(string)

Keywords

secure

FAQs

Package last updated on 03 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts