phantomauth
Version:
An authentication library with built-in security features, designed for fast and boilerplate-free backend development. Ideal for quickly building MVPs with a reasonable level of security. Not intended for high-risk or enterprise level use.
17 lines (16 loc) • 551 B
JavaScript
import crypto from 'crypto';
import base32 from 'base32';
export const decryptSec = (encryptedSec) => {
try {
const decipher = crypto.createDecipheriv(
process.env.CRYPTO_METHOD,
Buffer.from(process.env.ENCRYPTION_KEY, 'hex'),
Buffer.from(process.env.ENCRYPTION_IV, 'hex')
);
let decrypted = decipher.update(encryptedSec, 'hex', 'binary');
decrypted += decipher.final('binary');
return base32.encode(decrypted);
} catch (err) {
throw new Error(`Decryption failed: ${err.message}`);
}
}