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

@sunmi/secure

v1.1.0

Published

functions for security

Downloads

7

Readme

简介

用于处理约定的加解密操作,包括密码加密,请求体封装,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)