ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
PrivateKeyLoader.php
Go to the documentation of this file.
1 <?php
2 
3 namespace SAML2\Certificate;
4 
7 use SAML2\Configuration\PrivateKey as PrivateKeyConfiguration;
10 
12 {
20  public function loadPrivateKey(PrivateKeyConfiguration $key)
21  {
22  $privateKey = File::getFileContents($key->getFilePath());
23 
24  return PrivateKey::create($privateKey, $key->getPassPhrase());
25  }
26 
34  public function loadDecryptionKeys(
35  DecryptionProvider $identityProvider,
36  DecryptionProvider $serviceProvider
37  ) {
38  $decryptionKeys = new ArrayCollection();
39 
40  $senderSharedKey = $identityProvider->getSharedKey();
41  if ($senderSharedKey) {
43  $key->loadKey($senderSharedKey);
44  $decryptionKeys->add($key);
45 
46  return $decryptionKeys;
47  }
48 
49  $newPrivateKey = $serviceProvider->getPrivateKey(PrivateKeyConfiguration::NAME_NEW);
50  if ($newPrivateKey instanceof PrivateKeyConfiguration) {
51  $loadedKey = $this->loadPrivateKey($newPrivateKey);
52  $decryptionKeys->add($this->convertPrivateKeyToRsaKey($loadedKey));
53  }
54 
55  $privateKey = $serviceProvider->getPrivateKey(PrivateKeyConfiguration::NAME_DEFAULT, true);
56  $loadedKey = $this->loadPrivateKey($privateKey);
57  $decryptionKeys->add($this->convertPrivateKeyToRsaKey($loadedKey));
58 
59  return $decryptionKeys;
60  }
61 
68  private function convertPrivateKeyToRsaKey(PrivateKey $privateKey)
69  {
70  $key = new XMLSecurityKey(XMLSecurityKey::RSA_1_5, array('type' => 'private'));
71  $passphrase = $privateKey->getPassphrase();
72  if ($passphrase) {
73  $key->passphrase = $passphrase;
74  }
75 
76  $key->loadKey($privateKey->getKeyAsString());
77 
78  return $key;
79  }
80 }
static getFileContents($file)
Definition: File.php:18
convertPrivateKeyToRsaKey(PrivateKey $privateKey)
loadDecryptionKeys(DecryptionProvider $identityProvider, DecryptionProvider $serviceProvider)
Configuration of a private key.
Definition: PrivateKey.php:10
getPrivateKey($name, $required=false)
Simple Array implementation of Collection.
Create styles array
The data for the language used.
loadPrivateKey(PrivateKeyConfiguration $key)
Loads a private key based on the configuration given.
$key
Definition: croninfo.php:18
static create($keyContents, $passphrase=null)
Definition: PrivateKey.php:9