Skip to content
Open
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
13 changes: 7 additions & 6 deletions src/crypto/aes_transit_crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class AESTransitCrypto implements CryptoProvider {
cipherText = b64.escape(cipherText)

const masterCipher = crypto.createCipheriv(this.ALGORITHM, masterbuffer, iv)
let encDataKey = masterCipher.update(dataKey.toString("binary"), "binary", "base64")
let encDataKey = masterCipher.update(dataKey, undefined, "base64")
encDataKey += masterCipher.final("base64")
encDataKey = b64.escape(encDataKey)

Expand Down Expand Up @@ -48,11 +48,12 @@ export class AESTransitCrypto implements CryptoProvider {
const offset = keySize + ivSize + 7
const encDataKey = b64.unescape(ciphertext.substring(7 + ivSize, offset))
const masterCipher = crypto.createDecipheriv(this.ALGORITHM, masterBuffer, iv)

// Decrypt dataKey and reassign to a Buffer to decrypt the data
let dataKey = masterCipher.update(encDataKey, "base64", "binary")
dataKey += masterCipher.final("binary")
const byteKey = Buffer.from(dataKey, "binary")

// Decrypt dataKey directly into a Buffer
const decryptedKeyChunks: Buffer[] = [];
decryptedKeyChunks.push(masterCipher.update(encDataKey, "base64"));
decryptedKeyChunks.push(masterCipher.final());
const byteKey = Buffer.concat(decryptedKeyChunks)

const cipher = crypto.createDecipheriv(this.ALGORITHM, byteKey, iv)
let cipherText = cipher.update(b64.unescape(ciphertext.substring(offset)), "base64", "utf8")
Expand Down