You are here

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

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

File

src/Utilities.php, line 461

Class

Utilities
This file is part of miniOrange SAML plugin.

Namespace

Drupal\miniorange_saml

Code

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

  // 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;
}