# wechat-encodingaeskey

> 微信官方只提供了C++、php、Java、Python和C#版本的示例代码，看了官方算法和部分别人的轮子。造出这个轮子.本文在Node环境中测试通过，在浏览器中没有测试过。

Latest version **1.0.1** (published 2018-03-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install wechat-encodingaeskey
pnpm add wechat-encodingaeskey
yarn add wechat-encodingaeskey
bun add wechat-encodingaeskey
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-03-29 |
| First published | 2018-03-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Wos |
| Maintainers | flykeying |
| Keywords | wechat, aes, EncodingAESKey |

## Links

- npm: https://www.npmjs.com/package/wechat-encodingaeskey
- Repository: https://github.com/flykeying/sftp-sync-sc
- Homepage: https://github.com/flykeying/sftp-sync-sc#readme
- Issues: https://github.com/flykeying/sftp-sync-sc/issues
- npm.io page: https://npm.io/package/wechat-encodingaeskey

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads
- [datasets-fi-postalcodes](https://npm.io/package/datasets-fi-postalcodes.md) — 1.1K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2018-03-29
- 1.0.0 — 2018-03-29

## README

# wechat-encodingAESKey

微信官方只提供了C++、php、Java、Python和C#版本的示例代码，看了官方算法和部分别人的轮子。造出这个轮子.本文在Node环境中测试通过，在浏览器中没有测试过。

## 微信公众号消息加密解密，支持 node > 8.0

```shell
npm install wechat-encodingaeskey --save 
```


```javascript
 var WXCrypto = require('wechat-encodingAESKey');
 var wx = new WXCrypto(token, aesKey, appid);
 var encryptedXML = wx.encrypt(需要加密的字段, timestamp, nonce); // 加密 输出是字符串
 var decryptedXML = wx.decrypt(signature, timestamp, nonce, 加密的字符串); //解密 输出是xml
```

##提示##

timestamp,nonce,signature 自行解析来源，本程序在KOA2上测试成功，给出部分代码仅供参考

```javascript

var wx = new WXCrypto(token, aesKey, appid) //自行填写;
var decryptedXML = await wx.decrypt(ctx.query.msg_signature, ctx.query.timestamp, ctx.query.nonce, xml.Encrypt[0]);
````

## 解密后是xml格式，可以通过xml2json自行解析

```shell
npm install xml2json --save 
```

### js

```javascript
 xml2json
 var parseString = require('xml2js').parseString;
 var decryptedjson
 await parseString(decryptedXML, function (err, result) {
    decryptedjson = result
 });
 console.log( decryptedjson.xml.Content[0] )
```
 
 尤其Github上一篇代码，没找到出处，感谢所有轮主。

---
_Source: https://npm.io/package/wechat-encodingaeskey · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
