# tea-encrypt

> >项目勿删，desktop 有引用该项目

Latest version **1.4.4** (published 2019-09-24) · 0 weekly downloads

## Install

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

## 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.4.4 |
| Published | 2019-09-24 |
| First published | 2019-09-05 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 246.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Maintainers | zcorw |

## Links

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

## Dependencies (1)

- [node-gyp](https://npm.io/package/node-gyp.md) ^5.0.3

## Recent versions

- 1.4.4 (latest) — 2019-09-24
- 1.4.2 — 2019-09-24
- 1.4.1 — 2019-09-24
- 1.4.0 — 2019-09-05

## README

>项目勿删，desktop 有引用该项目

# C 加密扩展
利用 node-gyp 封装由 c 语言写的加密模块，生成 .node 文件供 nodejs 调用。

## 配置
node-gyp 项目下需要有 binding.gyp 作为配置。配置中最重要是定义原生模块：
`"targets": [{    "target_name": "addon1",    "sources": [ "1/addon.cc", "1/myobject.cc" ] }]`
上面配置的含义是模块名为 addon1，模块源码包括 "1/addon.cc", "1/myobject.cc"。（模块中所有引入的文件都要写上，不单单是入口文件）。

**小记：** node-gyp 是 c++ 编译器，如果待编译文件中有 c 文件，需要在 c++ 文件的引入头中用 extern "C"{} 将引入的 c 文件包裹起来。

## 执行命令
* node-gyp configure：项目构建前先执行这个命令，node-gyp 会根据系统下载对应的编译环境和所需的头文件；
* node-gyp build：项目开始构建生成对应系统的二进制文件，编译出来的二进制文件生成在 build/Release 文件夹中；
* node-gyp clean：删除 build 文件夹；
* node-gyp rebuild：按 clean - configure - build 执行一遍，重新编译。

## 进阶
经过上面方式编译出来的二进制文件要拿到 electron 中使用可能会报下面的错误：

```
NODE_MODULE_VERSION 64. This version of Node.js requires
NODE_MODULE_VERSION 69. Please try re-compiling or re-installing
```

这是因为在系统中安装的 nodejs 与 electron 的 NODE_MODULE_VERSION 不一样。node 与 electron 版本对应的 NODE_MODULE_VERSION 可通过 node-abi 查询。

要解决无法编译出适合指定版本 electron 的扩展，可以用下面两种方法：

1. 在 node-gyp 命令中指定编译的 electron 版本：  
   ```
   node-gyp build --target=4.1.3 --arch=x64 --dist-url=https://atom.io/download/ato-shell
   --target 指定 electron 版本
   --arch 设置模块为适应64位或32位操作系统而编译
   --dist-url 指定下载 electron 的 headers 的地址
   ``` 
   但这种方法有个缺陷，只能为每一个 electron 每一种操作系统去修改命令，这时就需要第二种方法。

2. 安装 electron-rebuild，只需直接执行 `electron-rebuild -v=4.1.3 -f` 就能编译出符合当前系统的指定 electron 版本的二进制文件，如果你是在 electron 项目中执行 `electron-rebuild`，甚至不需要指定 electron 版本。

很明显第二种方式更具有兼容性。

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