Socket
Book a DemoInstallSign in
Socket

@primno/dpapi

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@primno/dpapi

Pre-built version of DPAPI (Data Protection API of Windows). Encrypt and decrypt data.

2.0.1
latest
Source
npmnpm
Version published
Weekly downloads
574
43.5%
Maintainers
1
Weekly downloads
 
Created
Source

DPAPI

npm npm build coverage

Native module to encrypt/decrypt data on Windows with DPAPI.

This native module is prebuilt for Node.JS running on Windows. It provides the x64 and the arm64 N-API modules for Windows.

This package indicates if the prebuilt module is supported on the current platform.

Based on the port to N-API made by Microsoft in @msal-node-extension from the work of Brad Hughes.

This package is part of the Primno framework.

Why this package?

Other similar packages require to build the native module on the target machine during the installation. This means that you must have Python and Visual C++ installed, production environment included.

This package is prebuilt, so you don't need to have build tools installed on the target machine.

Install

The prebuilt module will be installed with the following command.

npm install @primno/dpapi

Definition

class Dpapi {
    public protectData(
        userData: Uint8Array,
        optionalEntropy: Uint8Array | null,
        scope: "CurrentUser" | "LocalMachine"
    ): Uint8Array;

    public unprotectData(
        encryptedData: Uint8Array,
        optionalEntropy: Uint8Array | null,
        scope: "CurrentUser" | "LocalMachine"
    ): Uint8Array;
}

const isPlatformSupported: boolean;

Usage

ECMAScript Module

import { Dpapi, isPlatformSupported } from "@primno/dpapi";

if (isPlatformSupported) {
    const buffer = Buffer.from("Hello world", "utf-8");

    const encrypted = Dpapi.protectData(buffer, null, "CurrentUser");
    const decrypted = Dpapi.unprotectData(encrypted, null, "CurrentUser");
}
else {
    console.error("Platform not supported. Only Windows is supported (x64, ARM64)");
}

CommonJS

const { Dpapi, isPlatformSupported } = require("@primno/dpapi");

if (isPlatformSupported) {
    const buffer = Buffer.from("Hello world", "utf-8");

    const encrypted = Dpapi.protectData(buffer, null, "CurrentUser");
    const decrypted = Dpapi.unprotectData(encrypted, null, "CurrentUser");
}
else {
    console.error("Platform not supported. Only Windows is supported (x64, ARM64)");
}

Credits

  • Brad Hughes for the original code.
  • Microsoft for the N-API port in MSAL-Node-Extension.

Keywords

Dpapi

FAQs

Package last updated on 12 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.