Skip to content
This repository has been archived by the owner on Dec 10, 2023. It is now read-only.

Commit

Permalink
added two functions to encrypt and decrypt the same string using secr…
Browse files Browse the repository at this point in the history
…et key
  • Loading branch information
chandra1899 committed May 31, 2023
1 parent 632ab68 commit f4ae389
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
14 changes: 12 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"bcryptjs": "^2.4.3",
"body-parser": "^1.20.1",
"cors": "^2.8.5",
"crypto-js": "^4.1.1",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"google-auth-library": "^8.7.0",
Expand Down
11 changes: 11 additions & 0 deletions utils/password.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dotev.config()

import crypto from 'crypto';
import jwt from 'jsonwebtoken';
import CryptoJS from "crypto-js";


export function getJwt(object,expiresIn='30d'){
Expand All @@ -26,3 +27,13 @@ export async function hash_password(password){
.toString("hex");
return genHash;
}

export async function encryptString(str){
const encrypted = await CryptoJS.AES.encrypt(str, process.env.SECRET);
return encrypted;
}

export async function dcryptString(encryptedStr){
const decrypted =await CryptoJS.AES.decrypt(encryptedStr, process.env.SECRET);
return decrypted;
}

0 comments on commit f4ae389

Please sign in to comment.