# enos-encrypt

> enos encrypt package

Latest version **0.0.9** (published 2020-12-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install enos-encrypt
pnpm add enos-encrypt
yarn add enos-encrypt
bun add enos-encrypt
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2020-12-03 |
| First published | 2019-08-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 9.7 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Author | envision-tc |
| Maintainers | envision-tc |
| Keywords | encrypt |

## Links

- npm: https://www.npmjs.com/package/enos-encrypt
- npm.io page: https://npm.io/package/enos-encrypt

## Dependencies (3)

- [random](https://npm.io/package/random.md) ^2.1.1
- [crypto-js](https://npm.io/package/crypto-js.md) 3.1.6
- [jsencrypt](https://npm.io/package/jsencrypt.md) ^3.0.0-rc.1

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 0.0.9 (latest) — 2020-12-03
- 0.0.8 — 2020-03-08
- 0.0.7 — 2019-08-23
- 0.0.6 — 2019-08-23
- 0.0.5 — 2019-08-21
- 0.0.4 — 2019-08-21
- 0.0.3 — 2019-08-21
- 0.0.2 — 2019-08-21
- 0.0.1 — 2019-08-21

## README

## ENOS-ENCRYPT 前端开发加密插件

### Installation

基于 NPM，安装方式如下

```
yarn add enos-encrypt
```

或者

```
npm i enos-encrypt
```

### USAGE

引入并创建实例

```js
import encrypt from 'enos-encrypt';

const encrypt = new Encrypt();
```

### 使用AES对称加密/解密

```js
// 加密
const textAfterEncrypt = encrypt.AES.encrypt('someText');
// 解密

encrypt.AES.decrypt(textAfterEncrypt); // 解密接受两个参数， 第一个为加密字串， 第二个为 option ={iv， key} 可以传入加密iv 和 key， 可以为空，默认使用创建实例时生成的IV key

```

### 使用RAS加密

```js
// 获取公钥
encrypt.RSA.getPublicKey('/app-portal/v1/encrypt/publicKey').then(() => {
   encrypt.RSA.encrypt('text'); // 如果encrypt 实例获取过公钥 
});

// 加密， 如果实例获取过公钥，将会使用实例 config 中的公钥，无需异步获取

encrypt.RSA.encrypt('text');
```

### API

#### 获取配置信息

```js
encrypt.config

// 返回如下

{
    iv: 'xxxx',
    aesKey: 'xxxxx',
    publicKeyId: 'xxxx',
    publicKey: 'xxxx'
}
```

#### AES加密

```JS
encrypt.AES.encrypt('str') // 接受一个参数，需要加密的字符串  
```

#### AES 解密

```JS
encrypt.AES.decrypt(encryptStr, options = {iv，key}) // 两个参数， 第一个解密密文， 第二个是可选项, 不传会使用实例加密时的iv key
```

#### RSA 获取公钥

##### 走服务端获取
```JS
encrypt.RSA.getPublicKey('/app-portal/v1/encrypt/publicKey');

// 返回Promise
```

##### 走本地获取
```js
encrypt.RSA.setPublicKey('${publicKey}', '${publicKeyId}');
```

#### RSA 加密

获取公钥以后，使用公钥加密
```js
encrypt.RSA.encrypt(str);
```

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