0
votes

Most examples of generating a public key from an Azure B2C modulus and exponent use phpseclib and pass an XML string to the library to generate a public key.

However, phpseclib3 appears to switch this up by providing a PublicKeyLoader that takes a keyed array where the keys are e and n for the exponent and modulus as BigInteger instances.

What transformations need to happen to those e and n values provided by Azure B2C to make them appropriate for use with the PublicKeyLoader?

Many of the examples for the older versions of phpseclib would convert from a base64url to base64, but I don't know if that is purely for the benefit of the XML conversion method and if that will work with the BigInteger function.

Generation of this public key is for the purposes of verifying an access token signature via lcobucci/jwt.

1

1 Answers

0
votes

After a bit of experimenting, and further searching the following method can be used.

Convert each value from base64url to base64 and decode. You might like to use the PHP package spomky-labs/base64url.

Unpack a value from hex

$value = unpack('H*', $value);

then convert to a BigInteger, using base 16

new BigInteger($value[1], 16);

The only bit to note is that some Base64URL decode examples add padding when preparing for the base64_decode. The cited lib does not, but it worked for me.