PHP Class RobRichards\XMLSecLibs\XMLSecurityKey

Copyright (c) 2007-2015, Robert Richards . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Robert Richards nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: Robert Richards ([email protected])
Show file Open project: robrichards/xmlseclibs Class Usage Examples

Public Properties

Property Type Description
$encryptedCtx RobRichards\XMLSecLibs\XMLSecEnc | null
$guid mixed | null
$isEncrypted boolean
$iv string | null
$key mixed | null
$keyChain mixed | null
$name string | null
$passphrase string
$type integer | string

Public Methods

Method Description
__construct ( string $type, null | array $params = null )
convertRSA ( string $modulus, string $exponent ) : string Hint: Modulus and Exponent must already be base64 decoded
decryptData ( string $data ) : mixed | string Decrypts the given data (string) using the regarding php-extension, depending on the library assigned to algorithm in the contructor.
encryptData ( string $data ) : mixed | string Encrypts the given data (string) using the regarding php-extension, depending on the library assigned to algorithm in the contructor.
fromEncryptedKeyElement ( DOMElemen\DOMElement $element ) : XMLSecurityKey Create key from an EncryptedKey-element.
generateSessionKey ( ) : string Generates a session key using the openssl-extension or using the mcrypt-extension as a fallback.
getAlgorith ( ) : mixed
getAlgorithm ( ) : mixed
getRawThumbprint ( string $cert ) : null | string Get the raw thumbprint of a certificate
getSymmetricKeySize ( ) : integer | null Retrieve the key size for the symmetric encryption algorithm.
getX509Certificate ( ) : string Retrieve the X509 certificate this key represents.
getX509Thumbprint ( ) : string Get the thumbprint of this X509 certificate.
loadKey ( string $key, boolean $isFile = false, boolean $isCert = false ) Loads the given key, or - with isFile set true - the key from the keyfile.
makeAsnSegment ( integer $type, string $string ) : null | string
serializeKey ( mixed $parent )
signData ( string $data ) : mixed | string Signs the data (string) using the extension assigned to the type in the constructor.
verifySignature ( string $data, string $signature ) : boolean | integer Verifies the data (string) against the given signature using the extension assigned to the type in the constructor.

Private Methods

Method Description
decryptMcrypt ( string $data ) : string Decrypts the given data (string) using the mcrypt-extension
decryptOpenSSL ( string $data ) : string Decrypts the given data (string) using the openssl-extension
encryptMcrypt ( string $data ) : string Encrypts the given data (string) using the mcrypt-extension
encryptOpenSSL ( string $data ) : string Encrypts the given data (string) using the openssl-extension
signOpenSSL ( string $data ) : string Signs the given data (string) using the openssl-extension
verifyOpenSSL ( string $data, string $signature ) : integer Verifies the given data (string) belonging to the given signature using the openssl-extension

Method Details

__construct() public method

public __construct ( string $type, null | array $params = null )
$type string
$params null | array

convertRSA() public static method

Hint: Modulus and Exponent must already be base64 decoded
public static convertRSA ( string $modulus, string $exponent ) : string
$modulus string
$exponent string
return string

decryptData() public method

Decrypts the given data (string) using the regarding php-extension, depending on the library assigned to algorithm in the contructor.
public decryptData ( string $data ) : mixed | string
$data string
return mixed | string

encryptData() public method

Encrypts the given data (string) using the regarding php-extension, depending on the library assigned to algorithm in the contructor.
public encryptData ( string $data ) : mixed | string
$data string
return mixed | string

fromEncryptedKeyElement() public static method

Create key from an EncryptedKey-element.
public static fromEncryptedKeyElement ( DOMElemen\DOMElement $element ) : XMLSecurityKey
$element DOMElemen\DOMElement The EncryptedKey-element.
return XMLSecurityKey The new key.

generateSessionKey() public method

In case of using DES3-CBC the key is checked for a proper parity bits set - Mcrypt doesn't care about the parity bits, but others may care.
public generateSessionKey ( ) : string
return string

getAlgorith() public method

See also: getAlgorithm()
Deprecation:
public getAlgorith ( ) : mixed
return mixed

getAlgorithm() public method

public getAlgorithm ( ) : mixed
return mixed

getRawThumbprint() public static method

Get the raw thumbprint of a certificate
public static getRawThumbprint ( string $cert ) : null | string
$cert string
return null | string

getSymmetricKeySize() public method

. If the key size is unknown, or this isn't a symmetric encryption algorithm, null is returned.
public getSymmetricKeySize ( ) : integer | null
return integer | null The number of bytes in the key.

getX509Certificate() public method

Will return the X509 certificate in PEM-format if this key represents an X509 certificate.
public getX509Certificate ( ) : string
return string The X509 certificate or null if this key doesn't represent an X509-certificate.

getX509Thumbprint() public method

Returns: The thumbprint as a lowercase 40-character hexadecimal number, or null if this isn't a X509 certificate.
public getX509Thumbprint ( ) : string
return string Lowercase 40-character hexadecimal number of thumbprint

loadKey() public method

Loads the given key, or - with isFile set true - the key from the keyfile.
public loadKey ( string $key, boolean $isFile = false, boolean $isCert = false )
$key string
$isFile boolean
$isCert boolean

makeAsnSegment() public static method

public static makeAsnSegment ( integer $type, string $string ) : null | string
$type integer
$string string
return null | string

serializeKey() public method

public serializeKey ( mixed $parent )
$parent mixed

signData() public method

Signs the data (string) using the extension assigned to the type in the constructor.
public signData ( string $data ) : mixed | string
$data string
return mixed | string

verifySignature() public method

Verifies the data (string) against the given signature using the extension assigned to the type in the constructor.
public verifySignature ( string $data, string $signature ) : boolean | integer
$data string
$signature string
return boolean | integer

Property Details

$encryptedCtx public property

public XMLSecEnc,RobRichards\XMLSecLibs|null $encryptedCtx
return RobRichards\XMLSecLibs\XMLSecEnc | null

$guid public property

public mixed|null $guid
return mixed | null

$isEncrypted public property

public bool $isEncrypted
return boolean

$iv public property

public string|null $iv
return string | null

$key public property

public mixed|null $key
return mixed | null

$keyChain public property

public mixed|null $keyChain
return mixed | null

$name public property

public string|null $name
return string | null

$passphrase public property

public string $passphrase
return string

$type public property

public int|string $type
return integer | string