简体   繁体   中英

Transform public key from apple in openssl public key

How can i use the public key from https://appleid.apple.com/auth/keys with openssl?

<?php
$key = '-----BEGIN PUBLIC KEY-----'. "\n".
chunk_split("1JiU4l3YCeT4o0gVmxGTEK1IXR-Ghdg5Bzka12tzmtdCxU00ChH66aV-4HRBjF1t95IsaeHeDFRgmF0lJbTDTqa6_VZo2hc0zTiUAsGLacN6slePvDcR1IMucQGtPP5tGhIbU-HKabsKOFdD4VQ5PCXifjpN9R-1qOR571BxCAl4u1kUUIePAAJcBcqGRFSI_I1j_jbN3gflK_8ZNmgnPrXA0kZXzj1I7ZHgekGbZoxmDrzYm2zmja1MsE5A_JX7itBYnlR41LOtvLRCNtw7K3EFlbfB6hkPL-Swk5XNGbWZdTROmaTNzJhV-lWT0gGm6V1qWAK2qOZoIDa_3Ud0Gw", 64).
'-----END PUBLIC KEY-----';

print_r($key);
$res = openssl_pkey_get_public($key);

print_r(openssl_pkey_get_details($res));



Fatal error: Uncaught TypeError: openssl_pkey_get_details(): Argument #1 ($key) must be of type OpenSSLAsymmetricKey

Your problem is the initial data from Apple (line 1). It isn't a public key, it's a JWKS, consisting of a modulus (n), exponent (e), and other useless stuff (in this case).

You need both the n value, which you have, and the e value, which is probably AQAB (65537).

Unfortunately, php openssl functions are a mess, so there's no builtin functionality for converting this.

Still, you can convert it to your initial $key value with some work.

The value of $key should now be what you expected.

References:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM