AES-GCM-256 output adds extra bytes? #953
Replies: 3 comments
-
CryptoKit version: guard let key = Data(base64Encoded: "hLbInPgDomkaXyl4M/5Vu8kJ7XSSHLJSNJFAXraMkVI="),
let iv = Data(base64Encoded: "vOOEV2pG/geYWezALcfVt2b1NG18+HnIzjca9c7FhXY=") else {
return
}
let message = Data("Hello World\n".utf8)
let aad = Data(hex: "6165b598c98a2f096d00017b")
do {
let skey = SymmetricKey(data: key)
let nonce = try CryptoKit.AES.GCM.Nonce(data: iv)
let box = try CryptoKit.AES.GCM.seal(message, using: skey, nonce: nonce, authenticating: aad)
let d = box.ciphertext
print("cipher: \(d.base64EncodedString()) length: \(d.count) tag: \(box.tag.base64EncodedString()) len: \(box.tag.count)")
} catch {
print("error with cryptokit: \(error)")
} output: It matches the Node.js output |
Beta Was this translation helpful? Give feedback.
-
Any update on this? If it wasn't clear, the CryptoKit version isn't an option for me since, afaik, it doesn't support streamed data with any kind of |
Beta Was this translation helpful? Give feedback.
-
Did you get an update on this? It seems to me that your node.js and cryptokit implementations do not use pkcs7 padding, as their output length is not divisible by 16, the block length of AES. Your implemention using CryptoSwift does use pkcs7 padding. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
This Node.js code below produces an output whose size is equal to the input size:
output:
enc: NHvJrsXYmiVeE8VO size: 12
authtag (base64):
LgqWVXwFrTfE2d/nquvsCg==
Fwict, Node.js uses pkcs7 padding by default unless a call is made to
cipher.setAutoPadding(false)
, and it throws if the input size isn't a multiple of the block size in that case.This CryptoSwift code adds an extra 4 bytes to the output:
output:
cipher: NHvJrsXYmiVeE8VOkCjvVg== count: 16 auth: nsDVw/NVoC1TV0ueJ7uXXw== count: 16
I'm not certain if this is a bug or if I need to change a setting somewhere. My actual need is the interoperability of these two implementations. More specifically, I'm trying to pass the ciphertext and auth tag from the node.js implementation to this CryptoSwift code:
output:
decrypted: He
It seems like it's still expecting the tag to be appended to the end of the ciphertext or something to that effect.
(I'm using the
update()
/finish()
methods here because I expect to use this with large files)Beta Was this translation helpful? Give feedback.
All reactions