Skip to content

Commit

Permalink
fix(electron): only call (de)cipher.setAAD() when aad is not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Mar 2, 2021
1 parent f7dd3e5 commit a5a6c4d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/runtime/node/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ async function gcmDecrypt(
try {
const cipher = createDecipheriv(algorithm, cek, iv, { authTagLength: 16 })
cipher.setAuthTag(tag)
cipher.setAAD(aad)
if (aad.byteLength) {
cipher.setAAD(aad)
}

return concat(cipher.update(ciphertext), cipher.final())
} catch (err) {
Expand Down
4 changes: 3 additions & 1 deletion src/runtime/node/encrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ async function gcmEncrypt(

const algorithm = <CipherGCMTypes>`aes-${keySize}-gcm`
const cipher = createCipheriv(algorithm, cek, iv, { authTagLength: 16 })
cipher.setAAD(aad)
if (aad.byteLength) {
cipher.setAAD(aad)
}

const ciphertext = concat(cipher.update(plaintext), cipher.final())
const tag = cipher.getAuthTag()
Expand Down

0 comments on commit a5a6c4d

Please sign in to comment.