# @wecom/crypto

> 企业微信加解密库，详见企业微信 API 文档 [加解密方案说明](https://work.weixin.qq.com/api/doc/90001/90148/91144) 和 [JS-SDK使用权限签名算法](https://work.weixin.qq.com/api/doc/90000/90136/90506)。

Latest version **1.0.1** (published 2022-01-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @wecom/crypto
pnpm add @wecom/crypto
yarn add @wecom/crypto
bun add @wecom/crypto
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-01-04 |
| First published | 2021-02-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | wecom-bot |

## Links

- npm: https://www.npmjs.com/package/@wecom/crypto
- npm.io page: https://npm.io/package/@wecom/crypto

## Recent versions

- 1.0.1 (latest) — 2022-01-04
- 1.0.0 — 2021-02-20

## README

# @wecom/crypto

企业微信加解密库，详见企业微信 API 文档 [加解密方案说明](https://work.weixin.qq.com/api/doc/90001/90148/91144) 和 [JS-SDK使用权限签名算法](https://work.weixin.qq.com/api/doc/90000/90136/90506)。

## 使用

```bash
# with npm
npm install @wecom/crypto
# with yarn
yarn add @wecom/crypto
```

## API

### 获取消息体签名

```typescript
import { getSignature } from '@wecom/crypto';

const signature = getSignature(token, timestamp, nonce, ciphered);

expect(signature).toEqual(query.signature);
```

### 解密消息

```typescript
import { decrypt } from '@wecom/crypto';

const { message, id } = decrypt(encodingAESKey, ciphered);

console.log({ message, id });
```

### 加密消息

```typescript
import { encrypt } from '@wecom/crypto';

const ciphered = encrypt(encodingAESKey, message, id);

console.log(ciphered);
```

### 获取 JS-SDK 签名

```typescript
import { getJsApiSignature } from '@wecom/crypto'

const { timestamp, nonceStr, signature } = getJsApiSignature({ url, ticket });

console.log({ timestamp, nonceStr, signature });
```

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