# tdes

> DES 加密算法与三重数据加密算法（Triple DES）的简易封装。

Latest version **1.0.2** (published 2019-07-21) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install tdes
pnpm add tdes
yarn add tdes
bun add tdes
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-07-21 |
| First published | 2019-07-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 37.6 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Zhang Yu |
| Maintainers | vincheung |
| Keywords | des, tdes, DES, Triple DES |

## Links

- npm: https://www.npmjs.com/package/tdes
- Repository: https://github.com/vincheung/tdes
- Homepage: https://github.com/vincheung/tdes#readme
- Issues: https://github.com/vincheung/tdes/issues
- npm.io page: https://npm.io/package/tdes

## Dependencies (1)

- [crypto-js](https://npm.io/package/crypto-js.md) ^3.1.9-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

- 1.0.2 (latest) — 2019-07-21
- 1.0.1 — 2019-07-17
- 1.0.0 — 2019-07-17

## README

# tdes

> DES 加密算法与三重数据加密算法（Triple DES）的简易封装。

## 说明

- DES 加密算法

  DES 全称为 Data Encryption Standard，即数据加密标准，是一种使用密钥加密的块算法

- 三重数据加密算法

  三重数据加密算法（Triple Data Encryption Algorithm，缩写为 TDEA，Triple DEA），或称 3DES（Triple DES），是一种对称密钥加密块密码，相当于是对每个数据块应用三次资料加密标准（DES）算法

## 使用

Install:

```shell
npm install tdes -S
```

Import:

```shell
<script src="../dist/tdes.min.js"></script>
```

## API

> tdes.js 的默认模式为 ECB，默认填充方式为 PKCS7

- des

  - desEncrypt

  - desDecrypt

```js
const tdes = require('../dist/tdes.min.js')
const message = 'https://github.com/vincheung'
const key = 'vincheng'

const ciphertext = tdes.desEncrypt(message, key)
const plaintext = tdes.desDecrypt(ciphertext, key)
console.log('\x1B[31m%s\x1B[0m', ciphertext)
console.log('\x1B[35m%s\x1B[0m', plaintext)

const ciphertext2 = tdes.desEncrypt(message, key, {
  mode: 'CBC',
  iv: 123
})
const plaintext2 = tdes.desDecrypt(ciphertext2, key, {
  mode: 'CBC',
  iv: 123
})
console.log('\x1B[36m%s\x1B[0m', ciphertext2)
console.log('\x1B[34m%s\x1B[0m', plaintext2)
```

- tdes

  - tdesEncrypt

  - tdesDecrypt

```js
const tdes = require('../dist/tdes.min.js')
const message = 'https://github.com/vincheung'
const key = 'vincheng'

const ciphertext = tdes.tdesEncrypt(message, key)
const plaintext = tdes.tdesDecrypt(ciphertext, key)
console.log('\x1B[31m%s\x1B[0m', ciphertext)
console.log('\x1B[35m%s\x1B[0m', plaintext)

const ciphertext2 = tdes.tdesEncrypt(message, key, {
  mode: 'CBC',
  iv: 123
})
const plaintext2 = tdes.tdesDecrypt(ciphertext2, key, {
  mode: 'CBC',
  iv: 123
})
console.log('\x1B[36m%s\x1B[0m', ciphertext2)
console.log('\x1B[34m%s\x1B[0m', plaintext2)
```

## 附注

- CBC 需要初始化向量 iv，来加密第一块 C0

- PKCS5 只能用来填充 64bit 的数据块

- 所有需要填充的地方都以 0 填充

- 在不填充的情况下，加密内容不是 8bit 整数倍加密会报错

- Java 的默认模式为 ECB，key 的 size 必须为 24。默认填充方式为 PKCS5，没有 PKCS7

- C# 的默认模式为 CBC，默认填充方式为 PKCS7

- JavaScript 填充方式 PKCS7 对应 Java 填充方式 PKCS5

## License

The MIT License.

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