File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -169,4 +169,39 @@ public function testDecodeByMultiJwkKeySet()
169169
170170 $ this ->assertSame ('bar ' , $ result ->sub );
171171 }
172+
173+ public function testParseKey ()
174+ {
175+ // Use a known module and exponent, and ensure it parses as expected
176+ $ jwk = [
177+ 'alg ' => 'RS256 ' ,
178+ 'kty ' => 'RSA ' ,
179+ 'n ' => 'hsYvCPtkUV7SIxwkOkJsJfhwV_CMdXU5i0UmY2QEs-Pa7v0-0y-s4EjEDtsQ8Yow6hc670JhkGBcMzhU4DtrqNGROXebyOse5FX0m0UvWo1qXqNTf28uBKB990mY42Icr8sGjtOw8ajyT9kufbmXi3eZKagKpG0TDGK90oBEfoGzCxoFT87F95liNth_GoyU5S8-G3OqIqLlQCwxkI5s-g2qvg_aooALfh1rhvx2wt4EJVMSrdnxtPQSPAtZBiw5SwCnVglc6OnalVNvAB2JArbqC9GAzzz9pApAk28SYg5a4hPiPyqwRv-4X1CXEK8bO5VesIeRX0oDf7UoM-pVAw ' ,
180+ 'use ' => 'sig ' ,
181+ 'e ' => 'AQAB ' ,
182+ 'kid ' => '838c06c62046c2d948affe137dd5310129f4d5d1 '
183+ ];
184+
185+ $ key = JWK ::parseKey ($ jwk );
186+ $ this ->assertNotNull ($ key );
187+
188+ $ openSslKey = $ key ->getKeyMaterial ();
189+ $ pubKey = openssl_pkey_get_public ($ openSslKey );
190+ $ keyData = openssl_pkey_get_details ($ pubKey );
191+
192+ $ expectedPublicKey = <<<EOF
193+ -----BEGIN PUBLIC KEY-----
194+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhsYvCPtkUV7SIxwkOkJs
195+ JfhwV/CMdXU5i0UmY2QEs+Pa7v0+0y+s4EjEDtsQ8Yow6hc670JhkGBcMzhU4Dtr
196+ qNGROXebyOse5FX0m0UvWo1qXqNTf28uBKB990mY42Icr8sGjtOw8ajyT9kufbmX
197+ i3eZKagKpG0TDGK90oBEfoGzCxoFT87F95liNth/GoyU5S8+G3OqIqLlQCwxkI5s
198+ +g2qvg/aooALfh1rhvx2wt4EJVMSrdnxtPQSPAtZBiw5SwCnVglc6OnalVNvAB2J
199+ ArbqC9GAzzz9pApAk28SYg5a4hPiPyqwRv+4X1CXEK8bO5VesIeRX0oDf7UoM+pV
200+ AwIDAQAB
201+ -----END PUBLIC KEY-----
202+
203+ EOF ;
204+
205+ $ this ->assertEquals ($ expectedPublicKey , $ keyData ['key ' ]);
206+ }
172207}
You can’t perform that action at this time.
0 commit comments