php - How to implement a concat KDF for use with JOSE/JWE/JWT -


text after "itemprop =" text ">

I try to write the code to decrypt a JWE token in PHP, as I do not support existing libraries algorithm I am doing ( A128CBC + HS256 , this is a excluded algorithm).

My problem is that I can not understand how to generate the content encryption key which uses the "Concatenation Key Derivation Function" (see Section 5.8.1 here).

I am based on my values.

So far, the relevant part of my code looks like this:

P>

  // Darey CBC encryption and episode; Integrity key $ shaSize = 256; $ Encryption size = $ shaSize / 2; $ IntegrityKisiz = $ shaSize; // Content // encryption key for $ encryptionSegments using Concat KDF = [$ masterkey key to derive the derivation, // z $ encryptionKeySize, // keydatalen $ this- & gt; PackInt32sBe ($ encryptionKeySize). Utf8_encode ('A128CBC + HS256'), // AlgorithmID $ this- & gt; PackInt32sBe (0), // PartyUInfo $ this-> PackInt32sBe (0), // PartyUInfo 'Encryption', // SuppPubInfo $ this- & gt; PackInt32sBe (1), // SuppPrivInfo]; // SHA256 Digest $ cek = hex2bin (calculate the hash ('sha256', implode ('', $ encryptionSegments));  

Potentially relevant, to obtain a big endian integer My function: Public function packInt32sBe ($ N) {if (Pack ('L', 1) === Pack ('N', 1)) {Return Pack ('L' , $ N);} Return Strerve (Pack ('L', $ N));}

shown here is not just the variable $ Masterkey The decrypted content is the master key.

I ended up solving it It's not certain whether it will help someone else, but just in case:

  // Darey CBC encryption & integrity key $ shaSize = 256; $ encryption size = $ ShaSize / 2; $ IntegrityKylej = $ shaSize; // CONSATT for content Calculate the key derivation using KDF // Encryption key $ encryption segments = [$ this-> PACK IN 32 SBE (1), $ Semicolon, // jade $ this-> Pack INS32 SBE ($ Encryption Keys) Utf8_encode ('A128CBC + HS256'), // AlgorithmID $ this- & gt; PackInt32sBe (0), // PartyUInfo $ this-> PackInt32sBe (0), // PartyUInfo 'encryption', // SuppPubInfo]; // SHA256 Digest, and then get it 16 bytes before $ cek = substr (hex 2 bean (hash ('sha256', implode ('', $ encryptionSegments), 0, 16);  

Here is the only unknown extreme $ cmk which is my content master key, "Z" value alias. In this specific case, I decrypt it by requesting the Xbox One token, Key found.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -