3 ms·
It looks like the plaintext is being padded so that its length is a multiple of the block size [1]. I can't find any resources that say you need to pad a messag
by ksbrooksjr 4y ago
It looks like the plaintext is being padded so that its length is a multiple of the block size [1]. I can't find any resources that say you need to pad a message before encrypting it with AES-GCM though. The official examples from MDN [2][3] don't pad the message before encrypting. The source code links to a wikipedia article that states that padding isn't necessary for counter mode, which the code is using (GCM is Galois Counter Mode)[4].
[1] https://github.com/mprimi/portable-secret/blob/6efdb4618216f0581b101c75a78ab460260c8a3d/creator/index.html#L160 https://github.com/mprimi/portable-secret/blob/6efdb4618216f...
[2] https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt#aes-gcm_2 https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypt...
[3] https://github.com/mdn/dom-examples/blob/main/web-crypto/encrypt-decrypt/aes-gcm.js https://github.com/mdn/dom-examples/blob/main/web-crypto/enc...
[4] https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS#5_and_PKCS#7:~:text=Streaming%20modes%20of%20operation%20can%20encrypt%20and%20decrypt%20messages%20of%20any%20size%20and%20therefore%20do%20not%20require%20padding https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS#5_....
- layer8 4y agoGCM doesn’t require padding (the calculation implicitly pads internally), unless you want to hide the length of the plaintext, as the resulting ciphertext will have the same length.