js-pbkdf2
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 JsPbkdf2 from 'js-pbkdf2';
const jsPbkdf2 = new JsPbkdf2(crypto);
const encrypt = await jsPbkdf2.encryptData('process.env.SECRET_KEY', JSON.stringify({example: 'example'}));
const encrypt2 = await jsPbkdf2.encryptData('process.env.SECRET_KEY', 'sample string');
const decrypt = await jsPbkdf2.decryptData('process.env.SECRET_KEY', 'WOwy8gEvHxEuLe0wl2A/cA==');
Usage to encrypt and decrypt backend
import JsPbkdf2 from 'js-pbkdf2';
import {webcrypto} from 'crypto';
const jsPbkdf2 = new JsPbkdf2(webcrypto);
const encrypt = await jsPbkdf2.encryptData('process.env.SECRET_KEY', JSON.stringify({example: 'example'}));
const encrypt2 = await jsPbkdf2.encryptData('process.env.SECRET_KEY', 'sample string');
const decrypt = await jsPbkdf2.decryptData('process.env.SECRET_KEY', 'WOwy8gEvHxEuLe0wl2A/cA==');
Sent http request
import JsPbkdf2 from 'js-pbkdf2';
const jsPbkdf2 = new JsPbkdf2(crypto);
const encrypt = await jsPbkdf2.encryptData('process.env.SECRET_KEY', 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(encrypt),
})
Status
Project | Status | Description |
---|---|---|
jsPbkdf2 | Password-Based Key encrypt and decrypt |