wwcrypto
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

wwcrypto

企业微信加解密库。各参数的含义请参考 企业微信 API 文档

Install

npm i wwcrypto

Usage

import WWCrypto from 'wwcrypto'
 
const wwcrypto = new WWCrypto(token, encodingAESKey, receiveId)
 
const encryptedMsg = wwcrypto.encryptMsg(message, { timestamp, nonce })
 
console.log(encryptedMsg)
// -> '<xml>[...]</xml>'
 
const decryptedMsg = wwcrypto.decryptMsg(signature, timestamp, nonce, encryptedMsg)
 
console.log(decryptedMsg)
// -> { AgentID, Content, ... }

API

WWCrypto( token, encodingAESKey, receiveId )

Params:

  • token: string
  • encodingAESKey: string
  • receiveId: string

初始化加解密库。

wwcrypto.decryptMsg( signature, timestamp, nonce, xml )

Params:

  • signature: string
  • timestamp: string | number
  • nonce: string | number
  • xml: string

Returns: Object

校验 signature 并解析 XML 消息内容。

wwcrypto.encryptMsg( message, [options] )

Params:

  • message: string
  • options: Object
    • nonce: string | number
    • timestamp: string | number
    • padding: Buffer

Returns: string

加密并封装消息,返回 XML 内容。可通过 options 配置 XML 消息的各类参数以及拼接在明文前的随机字节。

wwcrypto.decrypt( data )

Params:

  • data: string

Returns: string

解密消息。

wwcrypto.encrypt( data, options )

Params:

  • data: string
  • options: Object
    • padding: Buffer

Returns: string

加密消息,返回 base64 编码后的结果。可通过 options.padding 指定头部 16 个随机字节。

wwcrypto.getSignature( timestamp, nonce, encryptedMsg )

Params:

  • timestamp: string | number
  • nonce: string | number
  • encryptedMsg: string

Returns: string

计算签名。

Readme

Keywords

none

Package Sidebar

Install

npm i wwcrypto

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

11.8 kB

Total Files

5

Last publish

Collaborators

  • gzzhanghao