public function XMLSecurityKey::loadKey in SAML SP 2.0 Single Sign On (SSO) - SAML Service Provider 7
Loads the given key, or - with isFile set true - the key from the keyfile.
Parameters
string $key:
bool $isFile:
bool $isCert:
Throws
Exception
File
- includes/
XMLSecurityKey.php, line 355
Class
Code
public function loadKey($key, $isFile = false, $isCert = false) {
if ($isFile) {
$this->key = file_get_contents($key);
}
else {
$this->key = $key;
}
if ($isCert) {
$this->key = openssl_x509_read($this->key);
openssl_x509_export($this->key, $str_cert);
$this->x509Certificate = $str_cert;
$this->key = $str_cert;
}
else {
$this->x509Certificate = null;
}
if ($this->cryptParams['library'] == 'openssl') {
if ($this->cryptParams['type'] == 'public') {
if ($isCert) {
/* Load the thumbprint if this is an X509 certificate. */
$this->X509Thumbprint = self::getRawThumbprint($this->key);
}
$this->key = openssl_get_publickey($this->key);
if (!$this->key) {
throw new Exception('Unable to extract public key');
}
}
else {
$this->key = openssl_get_privatekey($this->key, $this->passphrase);
}
}
else {
if ($this->cryptParams['cipher'] == MCRYPT_RIJNDAEL_128) {
/* Check key length */
switch ($this->type) {
case self::AES256_CBC:
if (strlen($this->key) < 25) {
throw new Exception('Key must contain at least 25 characters for this cipher');
}
break;
case self::AES192_CBC:
if (strlen($this->key) < 17) {
throw new Exception('Key must contain at least 17 characters for this cipher');
}
break;
}
}
}
}