function testEncryptRSAOAEP_A256CBCHS512() { $jwe = new JOSE_JWE($this->plain_text); $jwe->encrypt($this->rsa_keys['public'], 'RSA-OAEP', 'A256CBC-HS512'); $jwe_decoded = JOSE_JWT::decode($jwe->toString()); $this->assertEquals($this->plain_text, $jwe_decoded->decrypt($this->rsa_keys['private'])->plain_text); }
function testVerifyInvalid() { $input = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIifQ.bVhBeMrW5g33Vi4FLSLn7aqcmAiupmmw-AY17YxCYLI-invalid'; $jwt = JOSE_JWT::decode($input); $this->setExpectedException('JOSE_Exception_VerificationFailed'); $res = $jwt->verify('secret'); }
function testEncryptDir_A128CBCHS256() { $secret = Random::string(256 / 8); $jwe = new JOSE_JWE($this->plain_text); $jwe = $jwe->encrypt($secret, 'dir'); $jwe_decoded = JOSE_JWT::decode($jwe->toString()); $this->assertEquals($this->plain_text, $jwe_decoded->decrypt($secret)->plain_text); }
function testVerifyMalformedJWS_RS256_to_HS256_with_explicit_alg() { $malformed_jwt = JOSE_JWT::decode($this->plain_jwt->sign($this->rsa_keys['public'], 'HS256')->toString()); $this->setExpectedException('PHPUnit_Framework_Error_Notice', 'Invalid signature'); $malformed_jwt->verify($this->rsa_keys['public'], 'RS256'); }
/** * Enforces that the ID Token is a \JOSE_JWT object * @param mixed $idToken * @return \JOSE_JWE|\JOSE_JWT */ private function getIdToken($idToken) { if (!$idToken instanceof \JOSE_JWT) { $idToken = \JOSE_JWT::decode($idToken); } return $idToken; }