I'm looking at JSON Web Encryption (JWE) and am left a bit confused about why you would use AES key wrapping.
The document even talks about using matching key algorithm strengths:
Algorithms of matching strengths should be used together whenever possible. For instance, when AES Key Wrap is used with a given key size, using the same key size is recommended when AES GCM is also used. If the key encryption and content encryption algorithms are different, the effective security is determined by the weaker of the two algorithms.
Essentially I'm wondering why you would use AES key wrap at all.
Example
So for an example comparison, using the A256GCM encryption algorithm I need a 256-bit key. Just to be easy my key will be "secret0123456789secret0123456789" and I'm encoding "Test".
DIR
Using direct (DIR) key algorithm (so using my key as the content key), I get:
eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..Vlf_WdLm-spHbfJe.RxMPrw.5VC8Y_qSPdSubbGNGyfn6A
This breaks down as:
JWE Header: {"alg":"dir","enc":"A256GCM"} Encrypted key (CEK): (blank) IV: Vlf_WdLm-spHbfJe Ciphertext: RxMPrw Authentication Tag: 5VC8Y_qSPdSubbGNGyfn6A
A256KW
Matching the key wrap algorithm with the encryption algorithm, I'll use a AES 256 bit key, which yields:
eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.66xZoxFI18zfvLMO6WU1zzqqX1tT8xu_qZzMQyPcfVuajPNkOJUXQA.X5ZL8yaOektXmfny.brz-Lg.xG-EvM-9hrw0XRiuRW7HrA
This breaks down as:
JWE Header: {"alg":"A256KW","enc":"A256GCM"} Encrypted key (CEK): 66xZoxFI18zfvLMO6WU1zzqqX1tT8xu_qZzMQyPcfVuajPNkOJUXQA IV: X5ZL8yaOektXmfny Ciphertext: brz-Lg Authentication Tag: xG-EvM-9hrw0XRiuRW7HrA
As I understand it, the content key is encrypted using JSON Web Key (JWK), but essentially what this is doing is:
- creating a random 256 bit content encryption key (CEK)
- encrypting the actual data with this CEK (and a random IV)
- encrypting the CEK with my supplied key
The encrypted CEK, IV, and encrypted data are all part of the resultant JWE object (all base64url encoded).
Direct JWE results in a smaller payload to be sent over-the-wire, and I would presume it's slightly faster to both encrypt and decrypt because it's skipping a step.
Does using AES key wrap yield higher security, and if so, why? If not, why would you use it instead of just direct content encryption?
PBES2-HSXXX+AXXXKW
. It does the same thing by using passing a passphrase in PBKDF2 before encrypting a randomly generated CEK to eventually encrypt the final plaintext content. It seemed unnecessary to have that extra randomly generated CEK, why not just use the PBKDF2's generated seed as the actual CEK itself. I guess the only benefit is the ability to rotate the passphrase without changing the CEK and re-encrypting the plaintext.