BeSimpleSoap/src/BeSimple/SoapCommon/WsSecurityKey.php

114 lines
2.5 KiB
PHP
Raw Normal View History

2011-11-01 11:12:07 +01:00
<?php
/*
* This file is part of BeSimpleSoapCommon.
*
* (c) Christian Kerl <christian-kerl@web.de>
* (c) Francis Besset <francis.besset@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace BeSimple\SoapCommon;
use ass\XmlSecurity\Key as XmlSecurityKey;
/**
* This class represents a security key for WS-Security (WSS).
*
* @author Andreas Schamberger <mail@andreass.net>
*/
class WsSecurityKey
{
/**
* Private key.
*
* @var \ass\XmlSecurity\Key
*/
protected $privateKey = null;
/**
* Public key.
*
* @var \ass\XmlSecurity\Key
*/
protected $publicKey = null;
/**
* Add private key.
*
* @param string $encryptionType Encryption type
* @param string $key Private key
* @param boolean $keyIsFile Given key parameter is path to key file
* @param string $passphrase Passphrase for key
* @return void
*/
public function addPrivateKey($encryptionType, $key = null, $keyIsFile = true, $passphrase = null)
{
$this->privateKey = XmlSecurityKey::factory($encryptionType, $key, $keyIsFile, XmlSecurityKey::TYPE_PRIVATE, $passphrase);
}
/**
* Add public key.
*
* @param string $encryptionType Encryption type
* @param string $key Public key
* @param boolean $keyIsFile Given key parameter is path to key file
* @return void
*/
public function addPublicKey($encryptionType, $key = null, $keyIsFile = true)
{
$this->publicKey = XmlSecurityKey::factory($encryptionType, $key, $keyIsFile, XmlSecurityKey::TYPE_PUBLIC);
}
/**
* Get private key.
*
* @return \ass\XmlSecurity\Key
*/
public function getPrivateKey()
{
return $this->privateKey;
}
/**
* Get public key.
*
* @return \ass\XmlSecurity\Key
*/
public function getPublicKey()
{
return $this->publicKey;
}
/**
* Has private and public key?
*
* @return boolean
*/
public function hasKeys()
{
return !is_null($this->privateKey) && !is_null($this->publicKey);
}
/**
* Has private key?
*
* @return boolean
*/
public function hasPrivateKey()
{
return !is_null($this->privateKey);
}
/**
* Has public key?
*
* @return boolean
*/
public function hasPublicKey()
{
return !is_null($this->publicKey);
}
}