# n-crypto

> 加密解密模块

Latest version **0.2.2** (published 2017-03-14) · ISC license · 0 weekly downloads

## Install

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

## 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.2.2 |
| Published | 2017-03-14 |
| First published | 2015-09-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | navyxie |
| Maintainers | navyxie |
| Keywords | MD5, RSA, DES, AES, 加密, 解密 |

## Links

- npm: https://www.npmjs.com/package/n-crypto
- Repository: https://github.com/navyxie/n-crypto
- Issues: https://github.com/navyxie/n-crypto/issues
- npm.io page: https://npm.io/package/n-crypto

## Dependencies (1)

- [utf8](https://npm.io/package/utf8.md) ^2.1.1

## Alternatives

- [adhdev](https://npm.io/package/adhdev.md) — 11.1K weekly downloads
- [react-slide-button](https://npm.io/package/react-slide-button.md) — 310 weekly downloads
- [better](https://npm.io/package/better.md) — 42 weekly downloads
- [react-native-swipe-image](https://npm.io/package/react-native-swipe-image.md) — 22 weekly downloads
- [nl.fokkezb.pulltorefresh](https://npm.io/package/nl.fokkezb.pulltorefresh.md) — 11 weekly downloads

## Recent versions

- 0.2.2 (latest) — 2017-03-14
- 0.2.1 — 2016-05-30
- 0.2.0 — 2016-04-05
- 0.1.4 — 2015-09-14
- 0.1.3 — 2015-09-14
- 0.1.2 — 2015-09-14
- 0.1.0 — 2015-09-14
- 0.0.4 — 2015-09-13
- 0.0.1 — 2015-09-10

## README

# 签名与验签&加密与解密
    算法说明：签名算法MD5和RSA(RSA-SHA1)，数据加密算法RSA(RSA_NO_PADDING,node > 0.10.0 && < 6.0.0),AES(aes-128-ecb),DES(des-ede3)，返回base64格式数据。
[![Build Status via Travis CI](https://travis-ci.org/navyxie/n-crypto.svg?branch=master)](https://travis-ci.org/navyxie/n-crypto) [![Coverage Status](https://coveralls.io/repos/github/navyxie/n-crypto/badge.svg?branch=master)](https://coveralls.io/github/navyxie/n-crypto?branch=master)


****

## 安装
    npm install n-crypto
## 初始化

```js
    var NCRYPTO = require('n-crypto');
    var nCrypto = new NCRYPTO({
		md5_key:'',//md5 key
		des_key:des_key:'',//des key,24个字符长度
		aes_key:aes_key:'',//aes key,16个字符长度
		merchant_pri_key:'',//rsa pri key
		npay_pub_key:'',//rsa pub  key
	})
```

## API

[`sign`](#sign)

[`verify`](#verify)

[`encrypt`](#encrypt)

[`decrypt`](#decrypt)


### 生成签名的API:sign

<a name="sign" />

```js
var encryptJson = {
	name:"navy",
	version:"1.0",
	country:"中国",
	age:201509110233
}
var sign_type = 'MD5'
var signVal = nCrypto.sign(encryptJson,sign_type);
console.log(signVal);//加密后返回的加密串
```

### 验证签名API:verify

<a name="verify" />

```js
var encryptJson = {
	name:"navy",
	version:"1.0",
	country:"中国",
	age:201509110233
}
var sign_type = 'MD5';
var md5Sign = 'a12b2084d8c7297a25fcfe452af8257c';
var verifyResult =  nCrypto.verify(encryptJson,md5Sign,sign_type);
console.log(verifyResult);//boolean值，true表示验签成功，false表示验签失败
```

### 加密数据的API:encrypt

<a name="encrypt" />

```js
var encryptJson = {
	name:"navy",
	version:"1.0",
	country:"中国",
	age:201509110233
}
var sign_type = 'AES'；//RSA(node>=0.12),AES,DES
var encryptData = nCrypto.encrypt(encryptJson,sign_type);//base64
console.log(encryptData);//加密后返回的base64加密串
```

### 解密数据的API:decrypt

<a name="decrypt" />

```js
var encryptJson = {
	name:"navy",
	version:"1.0",
	country:"中国",
	age:201509110233
}
var sign_type = 'AES'；//RSA(node>=0.12),AES,DES
var decryptData = nCrypto.decrypt(encryptJson,sign_type);//原始字符串
console.log(decryptData);//加密后返回的base64加密串
```

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