Simple 2 Way Text Encrypt and Decrypt

JS
S
JavaScript

Using npm package `cryptr`. Security standard: AES-256-CTR Do not use this to store passwords.

1const Cryptr = require('cryptr');
2
3const bwToken = '<^58:HpL+[Y9BXC';
4
5// 2 way hes-256-ctr hashing => not recommended to store passwords
6const cryptr = new Cryptr(bwToken);
7
8const encrypt = (data) => {
9   const strData = JSON.stringify(data);
10   return cryptr.encrypt(strData);
11}
12
13const decrypt = (dbEncryptedString) => {
14   const decryptedString = cryptr.decrypt(dbEncryptedString);
15   return JSON.parse(decryptedString);
16};
17
18// test
19const userData = { user: 'xpto', password: '1234'};
20const storeThis = encrypt(userData);
21console.log(storeThis);
22const decodeThis = decrypt(storeThis);
23console.log(decodeThis);

Created on 2/11/2019