Skip to content

Commit

Permalink
fix: throw typeerror if encrypt/decrypt values empty
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Jun 18, 2024
1 parent 0c7156f commit 2d4cc4c
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions helpers/encrypt-decrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function encrypt(
encryptionKey = env.HELPER_ENCRYPTION_KEY,
algorithm = 'aes-256-cbc'
) {
if (!text) throw new TypeError(`Text value missing`);
const iv = ivLength
? Buffer.from(crypto.randomBytes(ivLength))
.toString('hex')
Expand All @@ -41,6 +42,7 @@ function decrypt(
encryptionKey = env.HELPER_ENCRYPTION_KEY,
algorithm = 'aes-256-cbc'
) {
if (!text) throw new TypeError(`Text value missing`);
const textParts = text.includes('-') ? text.split('-') : [];
const iv = Buffer.from(textParts.shift() || '', 'binary');
const encryptedText = Buffer.from(textParts.join('-'), 'hex');
Expand Down

0 comments on commit 2d4cc4c

Please sign in to comment.