Skip to content
Open
Changes from 1 commit
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
10 changes: 6 additions & 4 deletions src/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ const AES_KEY = crypto.createHash('sha256')
.digest()

function encrypt (data) {
const cipher = crypto.createCipheriv('aes-256-ecb', AES_KEY, null)
return Buffer.concat([cipher.update(data), cipher.final()])
const iv = crypto.randomBytes(16)
const cipher = crypto.createCipheriv('aes-256-cbc', AES_KEY, iv)
Comment thread
anupamme marked this conversation as resolved.
Outdated
return Buffer.concat([iv, cipher.update(data), cipher.final()])
}

function decrypt (data) {
const decipher = crypto.createDecipheriv('aes-256-ecb', AES_KEY, null)
return Buffer.concat([decipher.update(data), decipher.final()])
const iv = data.subarray(0, 16)
const decipher = crypto.createDecipheriv('aes-256-cbc', AES_KEY, iv)
return Buffer.concat([decipher.update(data.subarray(16)), decipher.final()])
}

function calculateChecksum (data) {
Expand Down
Loading