diff --git a/test/integration/example/jwt/A2Test.php b/test/integration/example/jwt/A2Test.php new file mode 100644 index 0000000..cff39de --- /dev/null +++ b/test/integration/example/jwt/A2Test.php @@ -0,0 +1,148 @@ +assertEquals($expected, Base64::urlEncode($header->toJSON())); + return $header; + } + + public function testDecryptCEK() { + $algo = RSAESPKCS1Algorithm::fromPrivateKey(self::$_jwk); + $key = $algo->decrypt(self::$_encryptedCEK); + $this->assertEquals(32, strlen($key)); + return $key; + } + + /** + * @depends testDecryptCEK + */ + public function testEncrypt($cek) { + static $expectedCiphertextBase64 = <<encrypt(self::$_innerJWT, $cek, + self::$_iv, $aad); + $this->assertEquals($expectedCiphertext, $ciphertext); + $this->assertEquals($expectedAuthTag, $auth_tag); + return [$ciphertext, $auth_tag]; + } + + /** + * @depends testEncrypt + * @depends testDecryptCEK + * + * @param unknown $data + */ + public function testDecrypt($data, $cek) { + $header = Base64::urlEncode(self::$_joseJSON); + $key = Base64::urlEncode(self::$_encryptedCEK); + $iv = Base64::urlEncode(self::$_iv); + $ciphertext = Base64::urlEncode($data[0]); + $tag = Base64::urlEncode($data[1]); + $token = "$header.$key.$iv.$ciphertext.$tag"; + $jwe = JWE::fromCompact($token); + $key_algo = RSAESPKCS1Algorithm::fromPrivateKey(self::$_jwk); + $enc_algo = new A128CBCHS256Algorithm(); + $plaintext = $jwe->decrypt($key_algo, $enc_algo); + $this->assertEquals(self::$_innerJWT, $plaintext); + } +}