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

Commit

Permalink
Merge pull request #130 from chandra1899/issue_129
Browse files Browse the repository at this point in the history
Added two functions to encrypt and decrypt the same string using secr…
  • Loading branch information
BuddyLongLegs committed Jun 1, 2023
2 parents 632ab68 + f4ae389 commit cf8bf9b
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 cf8bf9b

Please sign in to comment.