# cedar-crypto

> > 项目采用国密算法，对 post 格式报文进行加密

Latest version **1.0.6-2** (published 2023-09-20) · 0 weekly downloads

## Install

```sh
npm install cedar-crypto
pnpm add cedar-crypto
yarn add cedar-crypto
bun add cedar-crypto
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6-2 |
| Published | 2023-09-20 |
| First published | 2023-05-29 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 737.4 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | lushuaii |

## Links

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

## Dependencies (3)

- [qs](https://npm.io/package/qs.md) ^6.11.2
- [axios](https://npm.io/package/axios.md) ^1.4.0
- [sm-crypto](https://npm.io/package/sm-crypto.md) ^0.3.12

## Recent versions

- 1.0.6-2 (latest) — 2023-09-20
- 1.0.6-1 — 2023-09-12
- 1.0.4 — 2023-07-26
- 1.0.1 — 2023-07-26
- 1.0.0 — 2023-05-29
- 0.0.15 — 2023-05-29

## README

# 报文加密工具

> 项目采用国密算法，对 post 格式报文进行加密

```ts
npm install cedar-crypto

yarn add cedar-crypto
```

```ts
// request.ts
import { encryptAxios, decryptAxios } from "cedar-crypto";

_axios.interceptors.request.use(
  async (config: standardConfig) => {
    // ...
    return encryptAxios(config, { publicKey: "041xxxxx", apiUrl: "/api" });
  },
  (error) => {
    //...
  }
);

_axios.interceptors.response.use(
  (res) => {
    // ...
    res = decryptAxios(res, {
      publicKey: "041xxxxx",
      apiUrl: "/api",
      checkResponse: false,
    });
    // ...
    return Promise.resolve(res);
  },
  (err) => {
    // ...
  }
);
```

```ts
interface Options {
  // 1. 服务端⽣成应⽤的公钥，线下下发公钥内容；
  publicKey: string;
  // baseurl
  apiUrl: string;
  // 是否校验相应报文摘要，不校验需要显示传值 false
  checkResponse: boolean;
}
```

对于某些无需加密的报文，可单独设置例外，组件会判断`config?.headers?.ignoreEnctype === true`

```ts
// 例如文件下载
export const exportRes = () =>
  defHttp.post({
    url: Api.exportXlsUrl,
    headers: { ignoreEnctype: true },
    responseType: "blob",
  });
```

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