Pre-built version of DPAPI (Data Protection API of Windows). Encrypt and decrypt data.
npm install @primno/dpapibash
npm install @primno/dpapi
`
Definition
`ts
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
$3
`ts
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)");
}
`
$3
`js
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)");
}
``