You are here

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

1 call to Utilities::castKey()
Utilities::validateSignature in includes/Utilities.php

File

includes/Utilities.php, line 876

Class

Utilities
This file is part of miniOrange SAML plugin.

Code

public static function castKey(XMLSecurityKey $key, $algorithm, $type = 'public') {

  //assert('is_string($algorithm)');

  //assert('$type === "public" || $type === "private"');

  // do nothing if algorithm is already the type of the key
  if ($key->type === $algorithm) {
    return $key;
  }
  $keyInfo = openssl_pkey_get_details($key->key);
  if ($keyInfo === FALSE) {
    echo sprintf('Unable to get key details from XMLSecurityKey.');
    exit;
  }
  if (!isset($keyInfo['key'])) {
    echo sprintf('Missing key in public key details.');
    exit;
  }
  $newKey = new XMLSecurityKey($algorithm, array(
    'type' => $type,
  ));
  $newKey
    ->loadKey($keyInfo['key']);
  return $newKey;
}