ahmadandika

Untitled

May 21st, 2021
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import crypto from 'crypto';
  2.  
  3. import { SECRET_KEY_AES, IV } from '../configs/keys';
  4.  
  5. export const encryptAes = data => {
  6. // const hashResult = await new Promise((resolve, reject) => {
  7. if (data) {
  8. const cipher = crypto.createCipheriv('aes-256-cbc', SECRET_KEY_AES, IV);
  9. let encrypted = cipher.update(data, 'utf8', 'base64');
  10. encrypted += cipher.final('base64');
  11. return encrypted;
  12. }
  13.  
  14. return null;
  15.  
  16. // // });
  17. // return hashResult;
  18. };
  19.  
  20. export const decryptAes = data => {
  21. // const hashResult = await new Promise((resolve, reject) => {
  22. const cipher = crypto.createDecipheriv('aes-256-cbc', SECRET_KEY_AES, IV);
  23. const decrypted = cipher.update(data, 'utf8', 'base64');
  24. return decrypted;
  25. // // });
  26. // return hashResult;
  27. };
  28.  
Add Comment
Please, Sign In to add comment