简体   繁体   English

openssl 公钥中从苹果转换公钥

[英]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?我如何使用https://appleid.apple.com/auth/keys和 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).您的问题是来自 Apple 的初始数据(第 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).它不是公钥,而是 JWKS,由模数 (n)、指数 (e) 和其他无用的东西(在本例中)组成。

You need both the n value, which you have, and the e value, which is probably AQAB (65537).您需要您拥有的n值和e值,这可能是AQAB (65537)。

Unfortunately, php openssl functions are a mess, so there's no builtin functionality for converting this.不幸的是, php openssl 函数是一团糟,所以没有用于转换它的内置功能。

Still, you can convert it to your initial $key value with some work.尽管如此,您仍然可以通过一些工作将其转换为您的初始$key值。

The value of $key should now be what you expected. $key的值现在应该是你所期望的。

References:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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