The problem is resolved.
It turns out that part of the X5C JSON array is a certificate, not a public key, so JSON decoding https://login.windows.net/common/discovery/keys and grabbing the X5C element and using openssl to get the public key works:
$cert_object = openssl_x509_read($cert); $pkey_object = openssl_pkey_get_public(cert_object); $pkey_array = openssl_pkey_get_details($pkey_object); $publicKey = $pkey_array ['key'];
In this example, $ cert is the value of X5C. However, this alone is not enough, since it is not encoded for the X509. So what I did was create a new file in the windows called certificate.cer, open it in notepad and put the X5C value there. Then, by double-clicking on the octet in the windows, going to the details tab and clicking "copy to file", the certificate export wizard opens.
Export in X509 format and upload to the server.
$cert = file_get_contents('Certificates/Public/public.cer');
Job! There is probably an easier way, but it works.
source share