# wincrypt

> Node.js wrapper around the Windows Data Protection API written in Rust.

Latest version **1.1.0** (published 2023-09-27) · Apache-2.0 license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2023-09-27 |
| First published | 2023-07-30 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 20 |
| Dependencies | 0 |
| Unpacked size | 290 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Angelo II |
| Maintainers | angelocore |

## Links

- npm: https://www.npmjs.com/package/wincrypt
- Repository: https://github.com/AngeloCore/wincrypt
- Homepage: https://github.com/AngeloCore/wincrypt#readme
- Issues: https://github.com/AngeloCore/wincrypt/issues
- Funding: https://paypal.me/AngeloCore
- npm.io page: https://npm.io/package/wincrypt

## Recent versions

- 1.1.0 (latest) — 2023-09-27
- 1.0.0-stable — 2023-07-30
- 1.0.0-1000 — 2023-07-30

## README

# WinCrypt

⚠️ Windows Only

> **[WinCrypt](https://npmjs.com/wincrypt)** is built in [rust](https://www.rust-lang.org/) and uses the native windows api's [CryptProtectData](https://learn.microsoft.com/en-us/windows/win32/api/dpapi/nf-dpapi-cryptprotectdata) and [CryptUnprotectData](https://learn.microsoft.com/en-us/windows/win32/api/dpapi/nf-dpapi-cryptunprotectdata) functions

## Example

```js
const wincrypt = require("wincrypt");

const text = Buffer.from("test");
const pass = Buffer.from("123");

const encrypted = wincrypt.protectData(text, pass);

console.log(wincrypt.unprotectData(encrypted, pass).toString()); // Prints "test"
```

## Types

```ts
export const enum Flags {
  CurrentUser = "CurrentUser",
  LocalMachine = "LocalMachine"
}

export function protectData(
  data: Buffer,
  optionalEntropy?: Buffer | undefined | null,
  flags?: Flags | undefined | null
): Buffer;

export function unprotectData(
  data: Buffer,
  optionalEntropy?: Buffer | undefined | null,
  flags?: Flags | undefined | null
): Buffer;
```

## Usage

### Without password

```js
wincrypt.protectData(Buffer.from("test"));
```

### With custom flag (only `CRYPTPROTECT_LOCAL_MACHINE` supported)

> INFO: Default flag is `0` ("CurrentUser")

```js
wincrypt.protectData(Buffer.from("test"), null, wincrypt.Flags.LocalMachine);
// or
wincrypt.protectData(Buffer.from("test"), null, "LocalMachine");
```

> The usage for `unprotectData` method is the same as `protectData`

© (C) Angelo II Apache-2.0 license, all right reserved

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