Skip to main content

js-pbkdf2

PBKDF2Js Create Release publish LICENSE Featured on Openbase

Password-Based Key: This library provides the functionality, and required a password to encrypt and decrypt data, can be use from frontend and backend. It can also send the encrypted data through http request.

Installation

npm i js-pbkdf2

Usage to encrypt and decrypt from frontend

import { encrypt, decrypt } from 'js-pbkdf2';

const encrypted = await encrypt('secret password', JSON.stringify({example: 'example'}));

const encrypt2 = await encrypt('secret password', 'sample string');

const decrypted = await decrypt('secret password', 'WOwy8gEvHxEuLe0wl2A/cA==');

Usage to encrypt and decrypt backend

import { encrypt, decrypt } from 'js-pbkdf2';

const encrypted = await encrypt('secret password', JSON.stringify({example: 'example'}));

const encrypt2 = await encrypt('process.env.SECRET_KEY', 'sample string');

const buf = await encrypt('process.env.SECRET_KEY', JSON.stringify({ id: 1, name: 'test', buffer: Buffer.from('hello'), typeArr: new Uint8Array([1, 2, 3]),}));

const decrypt = await jsPbkdf2.decryptData('process.env.SECRET_KEY', 'WOwy8gEvHxEuLe0wl2A/cA==');

Sent http request

import { encrypt, decrypt } from 'js-pbkdf2';

const encrypted = await encrypt('secret password', JSON.stringify({userName: 'example', password: 'sample'}));

fetch('https://127.0.0.1/api/sample', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
    },
    body: JSON.stringify(encrypted),    
})

Status

Project Status Description
jsPbkdf2 jsPbkdf2-status Password-Based Key encrypt and decrypt