示例#1
0
 /**
  * @throws \jwk\exceptions\InvalidJWKAlgorithm
  * @throws \jwk\exceptions\InvalidJWKType
  */
 public function testSignAndVerificationToken()
 {
     $claim_set = JWTClaimSetFactory::build(array(RegisteredJWTClaimNames::Issuer => 'joe', RegisteredJWTClaimNames::ExpirationTime => 1300819380, "http://example.com/is_root" => true, 'groups' => array('admin', 'sudo', 'devs')));
     $key = OctetSequenceJWKFactory::build(new OctetSequenceJWKSpecification(OctetSequenceJWKSpecification::GenerateSecret, JSONWebSignatureAndEncryptionAlgorithms::HS512));
     $key->setId('sym_key');
     $alg = new StringOrURI(JSONWebSignatureAndEncryptionAlgorithms::HS512);
     $jws = JWSFactory::build(new JWS_ParamsSpecification($key, $alg, $claim_set));
     $compact_serialization = $jws->toCompactSerialization();
     $this->assertTrue(!is_null($jws));
     $this->assertTrue(!empty($compact_serialization));
     $jws_1 = JWSFactory::build(new JWS_CompactFormatSpecification($compact_serialization));
     $this->assertTrue(!is_null($jws_1));
     $res = $jws_1->setKey($key)->verify($alg->getString());
     $this->assertTrue($res);
 }
 public function testDecryptDir()
 {
     $jwe_compact_form = 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0..Z0rVzErM4afxeyjYdxsg-z9g00G3oDsQKX0l8sTtSes.JJWRYo7YYy606qdg-Z2QcLe7mvg_k6MmXU5OjBOVG-lGySJMyy2i6zxqxFtikVWmghwloq-ABXgpPDOsXUz5KwiI1C1dYeG52lmkf0fTjjI5mV6waaZrNI42Ii4EEZTJm0PMJz-ElbqBGJUlwsmoIIEHPeI6nXT3wXwgrtcYf8-eDsr0W869GiPCylLxrecWzc8bD5Dlvpnmy9cIUKnm6WJIcLMbouuaHSC4BRS_nqV2aqHoLvqPNS17cshyFRiy7m8rWdr8cGWjD5HpJQclpm9hkdH6WvOg5JEHjKYaSByC4goGzst4CQ9BsC_PPF1Fq4PdI1OmhzIo0xPwCyOx9WmKM4SL8v3vD9WdsgBbeYTs1h67GSdiydF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Q7E-_22b0ak6f3RtLmd3HI.fwqQhABaFMFi-suUuhNPrw';
     $jwe_2 = JWEFactory::build(new JWE_CompactFormatSpecification($jwe_compact_form));
     $this->assertTrue(!is_null($jwe_2));
     //load shared key
     $shared_key = OctetSequenceJWKFactory::build(new OctetSequenceJWKSpecification('this_is_a_secret_key_long_enough', $jwe_2->getJOSEHeader()->getAlgorithm()->getString()));
     $shared_key->setKeyUse(JSONWebKeyPublicKeyUseValues::Encryption)->setId('shared_key');
     $jwe_2->setRecipientKey($shared_key);
     $payload_jws = $jwe_2->getPlainText();
     $this->assertTrue(!empty($payload_jws));
     $jws = JWSFactory::build(new JWS_CompactFormatSpecification($payload_jws));
     $this->assertTrue(!is_null($jws));
     // load server public key from pem format
     $server_key = RSAJWKFactory::build(new RSAJWKPEMPublicKeySpecification(TestKeys::$public_key_pem, JSONWebSignatureAndEncryptionAlgorithms::RS384));
     $server_key->setId('rsa_server');
     // and verify signature.
     $res = $jws->setKey($server_key)->verify(JSONWebSignatureAndEncryptionAlgorithms::RS384);
     $this->assertTrue($res);
 }