You are here

public static function XMLSecurityKey::convertRSA in SAML SP 2.0 Single Sign On (SSO) - SAML Service Provider 7

Hint: Modulus and Exponent must already be base64 decoded

Parameters

string $modulus:

string $exponent:

Return value

string

1 call to XMLSecurityKey::convertRSA()
XMLSecEnc::staticLocateKeyInfo in includes/XMLSecurityKey.php

File

includes/XMLSecurityKey.php, line 667

Class

XMLSecurityKey

Code

public static function convertRSA($modulus, $exponent) {

  /* make an ASN publicKeyInfo */
  $exponentEncoding = self::makeAsnSegment(0x2, $exponent);
  $modulusEncoding = self::makeAsnSegment(0x2, $modulus);
  $sequenceEncoding = self::makeAsnSegment(0x30, $modulusEncoding . $exponentEncoding);
  $bitstringEncoding = self::makeAsnSegment(0x3, $sequenceEncoding);
  $rsaAlgorithmIdentifier = pack("H*", "300D06092A864886F70D0101010500");
  $publicKeyInfo = self::makeAsnSegment(0x30, $rsaAlgorithmIdentifier . $bitstringEncoding);

  /* encode the publicKeyInfo in base64 and add PEM brackets */
  $publicKeyInfoBase64 = base64_encode($publicKeyInfo);
  $encoding = "-----BEGIN PUBLIC KEY-----\n";
  $offset = 0;
  while ($segment = substr($publicKeyInfoBase64, $offset, 64)) {
    $encoding = $encoding . $segment . "\n";
    $offset += 64;
  }
  return $encoding . "-----END PUBLIC KEY-----\n";
}