Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"@tiptap/pm": "^3.30.5",
"@tiptap/react": "^3.30.5",
"@tiptap/starter-kit": "^3.30.5",
"ai-kit": "github:bitbaum/ai-kit#v0.5.0",
"ai-kit": "github:bitbaum/ai-kit#v0.6.2",
"bcryptjs": "^2.4.3",
"busboy": "^1.6.0",
"clsx": "^2.1.1",
Expand Down Expand Up @@ -161,7 +161,7 @@
"@types/jest": "^30.0.0",
"@types/jsonwebtoken": "^9.0.5",
"@types/leaflet": "^1.9.22",
"@types/node": "^20.19.43",
"@types/node": "^26.4.0",
"@types/nodemailer": "^7.0.1",
"@types/pg": "^8.23.1",
"@types/qrcode": "^1.5.6",
Expand Down
18 changes: 14 additions & 4 deletions src/lib/payments/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,25 @@ export function maskSensitiveData(data: string): string {
return masked
}

/**
* Derive a 32-byte AES-256 key from the configured secret.
* createCipher/createDecipher were removed in Node 22 (and never supported
* GCM), so we hash the secret to a fixed-length key for createCipheriv.
*/
function deriveEncryptionKey(): Buffer {
const secret = process.env.PAYMENT_ENCRYPTION_KEY || 'default-key-change-in-production'
return crypto.createHash('sha256').update(secret).digest()
}

/**
* Encrypt sensitive data before storage
*/
export function encryptSensitiveData(data: string): string {
const algorithm = 'aes-256-gcm'
const key = process.env.PAYMENT_ENCRYPTION_KEY || 'default-key-change-in-production'
const key = deriveEncryptionKey()
const iv = crypto.randomBytes(16)

const cipher = crypto.createCipher(algorithm, key)
const cipher = crypto.createCipheriv(algorithm, key, iv)
let encrypted = cipher.update(data, 'utf8', 'hex')
encrypted += cipher.final('hex')

Expand All @@ -102,8 +112,8 @@ export function decryptSensitiveData(encryptedData: string): string {
try {
const { encrypted, iv, authTag, algorithm } = JSON.parse(encryptedData)

const key = process.env.PAYMENT_ENCRYPTION_KEY || 'default-key-change-in-production'
const decipher = crypto.createDecipher(algorithm, key)
const key = deriveEncryptionKey()
const decipher = crypto.createDecipheriv(algorithm, key, Buffer.from(iv, 'hex'))
decipher.setAuthTag(Buffer.from(authTag, 'hex'))

let decrypted = decipher.update(encrypted, 'hex', 'utf8')
Expand Down
Loading