# feathers-encryption-hook

> [![Build Status](https://app.travis-ci.com/ydeshayes/feathers-encryption-hook.svg?branch=main)](https://app.travis-ci.com/ydeshayes/feathers-encryption-hook) # Feathers encryption hook

Latest version **1.0.1** (published 2023-01-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install feathers-encryption-hook
pnpm add feathers-encryption-hook
yarn add feathers-encryption-hook
bun add feathers-encryption-hook
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-01-21 |
| First published | 2023-01-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=6.0.0 |
| Dependencies | 1 |
| Unpacked size | 35.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | ydeshayes |
| Maintainers | ydeshayes |
| Keywords | feathersjs, hook, encryption |

## Links

- npm: https://www.npmjs.com/package/feathers-encryption-hook
- Repository: https://github.com/ydeshayes/feathers-encryption-hook
- Homepage: https://github.com/ydeshayes/feathers-encryption-hook#readme
- Issues: https://github.com/ydeshayes/feathers-encryption-hook/issues
- npm.io page: https://npm.io/package/feathers-encryption-hook

## Dependencies (1)

- [@feathersjs/feathers](https://npm.io/package/@feathersjs/feathers.md) ^4.5.15

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2023-01-21
- 1.0.0 — 2023-01-10

## README

[![Build Status](https://app.travis-ci.com/ydeshayes/feathers-encryption-hook.svg?branch=main)](https://app.travis-ci.com/ydeshayes/feathers-encryption-hook)
# Feathers encryption hook

This feathers hook is handling encryption in database for selected fields. It can encrypt before and decrypt data after.

### Importing library

You can import the generated bundle to use the whole library generated by this starter:

```javascript
import encryptionHook from 'feathers-encryption-hook'
```

Additionally, you can import the transpiled modules from `dist/lib` in case you have a modular library:

```javascript
import encryptionHook from 'feathers-encryption-hook/dist/lib/feathers-hook-encrypt'
```

## Usage

### Configuration

You can use the authentication configuration:

```js
app.set("authentication", {
    secret: "secret",
    algorithm: "aes-256-cfb"
});
```

Create an encryption object in your configuation:

```js
"encryption", {
    key: "key",
    algorithm: "aes-256-cbc"
}
```

 or give the key and algorithm at the hook init:
```js
import encryptionHookInit from 'feathers-encryption-hook';

const encryptionHook = encryptionHookInit({
    algorithm: "aes-256-cbc",
    key: "*F-JaNdRgUkXp2r5u8x/A?D(G+KbPeSh",
    fields: ["foo"]
});
app.service('messages').hooks({
    before: {
        create: [encryptionHook]
    },
    after: {
        create: [encryptionHook]
    }
});
```

Used in a before hook it will encrypt the fields in `fields`.
Used in a after hook it will decrypt the fields in `fields`.
# Development

### NPM scripts

 - `npm t`: Run test suite
 - `npm start`: Run `npm run build` in watch mode
 - `npm run test:watch`: Run test suite in [interactive watch mode](http://facebook.github.io/jest/docs/cli.html#watch)
 - `npm run test:prod`: Run linting and generate coverage
 - `npm run build`: Generate bundles and typings, create docs
 - `npm run lint`: Lints code
 - `npm run commit`: Commit using conventional commit style [husky](https://github.com/typicode/husky)

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