1 | <?php |
||
19 | * |
||
20 | * @see https://tools.ietf.org/html/draft-ietf-jose-json-web-encryption-39#appendix-A.3.3 |
||
21 | */ |
||
22 | final class JWETest extends TestCase |
||
23 | { |
||
24 | public function testCEKEncryption() |
||
25 | { |
||
26 | // The KEK |
||
27 | $kek = base64_decode('GawgguFyGrWKav7AX4VKUg'); |
||
28 | |||
29 | // The CEK to encrypt (we convert it into a binary string) |
||
30 | $data = [4, 211, 31, 197, 84, 157, 252, 254, 11, 100, 157, 250, 63, 170, 106, 206, 107, 124, 212, 45, 111, 107, 9, 219, 200, 177, 0, 240, 143, 156, 44, 207]; |
||
31 | foreach ($data as $key => $value) { |
||
32 | $data[$key] = str_pad(dechex($value), 2, '0', STR_PAD_LEFT); |
||
33 | } |
||
34 | $data = hex2bin(implode('', $data)); |
||
35 | |||
36 | $wrapped = A128KW::wrap($kek, $data); |
||
37 | $this->assertEquals(base64_decode('6KB707dM9YTIgHtLvtgWQ8mKwboJW3of9locizkDTHzBC2IlrT1oOQ'), $wrapped); |
||
38 | $unwrapped = A128KW::unwrap($kek, $wrapped); |
||
39 | $this->assertEquals($data, $unwrapped); |
||
42 |